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"
32 #include "imap_private.h"
35 #include "mutt_crypt.h"
44 #include "lib/debug.h"
54 static const char *No_mailbox_is_open = N_("No mailbox is open.");
55 static const char *There_are_no_messages = N_("There are no messages.");
56 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
57 static const char *Function_not_permitted_in_attach_message_mode =
58 N_("Function not permitted in attach-message mode.");
59 static const char *No_visible = N_("No visible messages.");
61 #define CHECK_MSGCOUNT if (!Context) \
64 mutt_error(_(No_mailbox_is_open)); \
67 else if (!Context->msgcount) \
70 mutt_error(_(There_are_no_messages)); \
74 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
77 mutt_error(_(No_visible)); \
82 #define CHECK_READONLY if (Context->readonly) \
85 mutt_error(_(Mailbox_is_read_only)); \
89 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
92 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
96 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
97 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
98 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
100 extern const char *ReleaseDate;
101 extern size_t UngetCount;
103 static void set_xterm_title_bar (char *title)
105 fputs ("\033]2;", stdout);
106 fputs (title, stdout);
107 fputs ("\007", stdout);
111 static void set_xterm_icon_name (char *name)
113 fputs ("\033]1;", stdout);
114 fputs (name, stdout);
115 fputs ("\007", stdout);
119 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
122 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
123 int edgemsgno, reverse = Sort & SORT_REVERSE;
124 HEADER *h = Context->hdrs[Context->v2r[num]];
127 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
128 flag |= M_FORMAT_TREE; /* display the thread tree */
129 if (h->display_subject)
130 flag |= M_FORMAT_FORCESUBJ;
133 if (menu->top + menu->pagelen > menu->max)
134 edgemsgno = Context->v2r[menu->max - 1];
136 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
139 edgemsgno = Context->v2r[menu->top];
141 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
145 /* if no ancestor is visible on current screen, provisionally force
147 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
149 flag |= M_FORMAT_FORCESUBJ;
152 else if (tmp->message->virtual >= 0)
155 if (flag & M_FORMAT_FORCESUBJ) {
156 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
160 /* ...but if a previous sibling is available, don't force it */
161 if (reverse ? tmp->message->msgno >
162 edgemsgno : tmp->message->msgno < edgemsgno)
164 else if (tmp->message->virtual >= 0) {
165 flag &= ~M_FORMAT_FORCESUBJ;
173 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
176 int index_color (int index_no)
178 HEADER *h = Context->hdrs[Context->v2r[index_no]];
183 mutt_set_header_color (Context, h);
187 static int ci_next_undeleted (int msgno)
191 for (i = msgno + 1; i < Context->vcount; i++)
192 if (!Context->hdrs[Context->v2r[i]]->deleted)
197 static int ci_previous_undeleted (int msgno)
201 for (i = msgno - 1; i >= 0; i--)
202 if (!Context->hdrs[Context->v2r[i]]->deleted)
207 /* Return the index of the first new message, or failing that, the first
210 static int ci_first_message (void)
214 if (Context && Context->msgcount) {
215 for (i = 0; i < Context->vcount; i++) {
216 if (!Context->hdrs[Context->v2r[i]]->read &&
217 !Context->hdrs[Context->v2r[i]]->deleted) {
218 if (!Context->hdrs[Context->v2r[i]]->old)
227 /* If Sort is reverse and not threaded, the latest message is first.
228 * If Sort is threaded, the latest message is first iff exactly one
229 * of Sort and SortAux are reverse.
231 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
232 ((Sort & SORT_MASK) == SORT_THREADS &&
233 ((Sort ^ SortAux) & SORT_REVERSE)))
236 return (Context->vcount ? Context->vcount - 1 : 0);
241 /* This should be in mx.c, but it only gets used here. */
242 static int mx_toggle_write (CONTEXT * ctx)
248 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
253 if (ctx->dontwrite) {
255 mutt_message (_("Changes to folder will be written on folder exit."));
259 mutt_message (_("Changes to folder will not be written."));
265 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
266 int oldcount, int index_hint)
268 /* store pointers to the newly added messages */
269 HEADER **save_new = NULL;
272 /* take note of the current message */
274 if (menu->current < Context->vcount)
275 menu->oldcurrent = index_hint;
277 oldcount = 0; /* invalid message number! */
280 /* We are in a limited view. Check if the new message(s) satisfy
281 * the limit criteria. If they do, set their virtual msgno so that
282 * they will be visible in the limited view */
283 if (Context->pattern) {
284 #define THIS_BODY Context->hdrs[j]->content
285 if (oldcount || check == M_REOPENED) {
286 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount;
288 if (mutt_pattern_exec
289 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
291 Context->hdrs[j]->virtual = Context->vcount;
292 Context->v2r[Context->vcount] = j;
293 Context->hdrs[j]->limited = 1;
296 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
303 /* save the list of new messages */
304 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
306 (HEADER **) safe_malloc (sizeof (HEADER *) *
307 (Context->msgcount - oldcount));
308 for (j = oldcount; j < Context->msgcount; j++)
309 save_new[j - oldcount] = Context->hdrs[j];
312 /* if the mailbox was reopened, need to rethread from scratch */
313 mutt_sort_headers (Context, (check == M_REOPENED));
315 /* uncollapse threads with new mail */
316 if ((Sort & SORT_MASK) == SORT_THREADS) {
317 if (check == M_REOPENED) {
320 Context->collapsed = 0;
322 for (h = Context->tree; h; h = h->next) {
323 for (j = h; !j->message; j = j->child);
324 mutt_uncollapse_thread (Context, j->message);
326 mutt_set_virtual (Context);
329 for (j = 0; j < Context->msgcount - oldcount; j++) {
332 for (k = 0; k < Context->msgcount; k++) {
333 HEADER *h = Context->hdrs[k];
335 if (h == save_new[j] && (!Context->pattern || h->limited))
336 mutt_uncollapse_thread (Context, h);
340 mutt_set_virtual (Context);
346 /* restore the current message to the message it was pointing to */
347 for (j = 0; j < Context->vcount; j++) {
348 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
355 if (menu->current < 0)
356 menu->current = ci_first_message ();
360 static void resort_index (MUTTMENU * menu)
363 HEADER *current = CURHDR;
366 mutt_sort_headers (Context, 0);
367 /* Restore the current message */
369 for (i = 0; i < Context->vcount; i++) {
370 if (Context->hdrs[Context->v2r[i]] == current) {
376 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
377 menu->current = mutt_parent_message (Context, current);
379 if (menu->current < 0)
380 menu->current = ci_first_message ();
382 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
385 struct mapping_t IndexHelp[] = {
386 {N_("Quit"), OP_QUIT},
387 {N_("Del"), OP_DELETE},
388 {N_("Undel"), OP_UNDELETE},
389 {N_("Save"), OP_SAVE},
390 {N_("Mail"), OP_MAIL},
391 {N_("Reply"), OP_REPLY},
392 {N_("Group"), OP_GROUP_REPLY},
393 {N_("Help"), OP_HELP},
398 struct mapping_t IndexNewsHelp[] = {
399 {N_("Quit"), OP_QUIT},
400 {N_("Del"), OP_DELETE},
401 {N_("Undel"), OP_UNDELETE},
402 {N_("Save"), OP_SAVE},
403 {N_("Post"), OP_POST},
404 {N_("Followup"), OP_FOLLOWUP},
405 {N_("Catchup"), OP_CATCHUP},
406 {N_("Help"), OP_HELP},
411 /* This function handles the message index window as well as commands returned
412 * from the pager (MENU_PAGER).
414 int mutt_index_menu (void)
416 char buf[LONG_STRING], helpstr[SHORT_STRING];
419 int done = 0; /* controls when to exit the "event" loop */
421 int tag = 0; /* has the tag-prefix command been pressed? */
426 char *cp; /* temporary variable. */
427 int index_hint; /* used to restore cursor position */
428 int do_buffy_notify = 1;
429 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
430 int attach_msg = option (OPTATTACHMSG);
432 menu = mutt_new_menu ();
433 menu->menu = MENU_MAIN;
435 menu->pagelen = LINES - 3;
436 menu->make_entry = index_make_entry;
437 menu->color = index_color;
438 menu->current = ci_first_message ();
439 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
442 && (Context->magic ==
443 M_NNTP)) ? IndexNewsHelp :
448 buffy_check (1); /* force the buffy check after we enter the folder */
449 /* record folder we open to place sidebar indicator properly */
450 if (Context && Context->path)
451 sidebar_set_current (Context->path);
455 tag = 0; /* clear the tag-prefix */
457 menu->max = Context ? Context->vcount : 0;
458 oldcount = Context ? Context->msgcount : 0;
460 /* check if we need to resort the index because just about
461 * any 'op' below could do mutt_enter_command(), either here or
462 * from any new menu launched, and change $sort/$sort_aux
464 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
467 if (option (OPTREDRAWTREE) && Context && Context->msgcount
468 && (Sort & SORT_MASK) == SORT_THREADS) {
469 mutt_draw_tree (Context);
470 menu->redraw |= REDRAW_STATUS;
471 unset_option (OPTREDRAWTREE);
474 if (Context && !attach_msg) {
477 /* check for new mail in the mailbox. If nonzero, then something has
478 * changed about the file (either we got new mail or the file was
479 * modified underneath us.)
483 imap_allow_reopen (Context);
486 index_hint = (Context->vcount && menu->current >= 0
487 && menu->current < Context->vcount) ? CURHDR->index : 0;
489 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
490 if (!Context->path) {
491 /* fatal error occurred */
493 menu->redraw = REDRAW_FULL;
495 set_option (OPTSEARCHINVALID);
497 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
498 update_index (menu, Context, check, oldcount, index_hint);
500 /* notify the user of new mail */
501 if (check == M_REOPENED)
503 ("Mailbox was externally modified. Flags may be wrong."));
504 else if (check == M_NEW_MAIL) {
505 /* on new mail: redraw sidebar */
506 sidebar_draw (CurrentMenu);
507 mutt_message (_("New mail in this mailbox."));
509 if (option (OPTBEEPNEW))
512 else if (check == M_FLAGS)
513 mutt_message (_("Mailbox was externally modified."));
515 /* avoid the message being overwritten by buffy */
518 menu->redraw = REDRAW_FULL;
519 menu->max = Context->vcount;
521 set_option (OPTSEARCHINVALID);
527 imap_disallow_reopen (Context);
531 /* check for new mail in the incoming folders */
533 if ((newcount = buffy_check (0)) != oldcount) {
534 menu->redraw |= REDRAW_STATUS;
535 menu->redraw |= REDRAW_SIDEBAR;
537 if (do_buffy_notify) {
538 if (buffy_notify () && option (OPTBEEPNEW))
547 if (menu->redraw & REDRAW_SIDEBAR)
548 sidebar_draw (menu->menu);
549 if (menu->redraw & REDRAW_FULL) {
550 menu_redraw_full (menu);
551 sidebar_draw (menu->menu);
555 if (menu->menu == MENU_MAIN) {
556 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
557 menu_check_recenter (menu);
559 if (menu->redraw & REDRAW_INDEX) {
560 menu_redraw_index (menu);
561 menu->redraw |= REDRAW_STATUS;
563 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
564 menu_redraw_motion (menu);
565 else if (menu->redraw & REDRAW_CURRENT)
566 menu_redraw_current (menu);
569 if (menu->redraw & REDRAW_STATUS) {
571 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
573 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
574 SETCOLOR (MT_COLOR_STATUS);
575 mutt_paddstr (COLS, buf);
576 SETCOLOR (MT_COLOR_NORMAL);
577 sidebar_set_buffystats (Context);
578 menu->redraw &= ~REDRAW_STATUS;
579 if (option (OPTXTERMSETTITLES)) {
580 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
581 set_xterm_title_bar (buf);
582 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
583 set_xterm_icon_name (buf);
588 if (menu->current < menu->max)
589 menu->oldcurrent = menu->current;
591 menu->oldcurrent = -1;
593 if (option (OPTARROWCURSOR))
594 move (menu->current - menu->top + menu->offset, 2);
596 move (menu->current - menu->top + menu->offset, COLS - 1);
599 op = km_dokey (MENU_MAIN);
601 debug_print (4, ("Got op %d\n", op));
603 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
606 mutt_resize_screen ();
607 menu->redraw = REDRAW_FULL;
608 menu->menu = MENU_MAIN;
610 menu->top = 0; /* so we scroll the right amount */
612 * force a real complete redraw. clrtobot() doesn't seem to be able
613 * to handle every case without this.
615 clearok (stdscr, TRUE);
621 continue; /* either user abort or timeout */
625 /* special handling for the tag-prefix function */
626 if (op == OP_TAG_PREFIX) {
628 mutt_error (_("No mailbox is open."));
633 if (!Context->tagged) {
634 mutt_error (_("No tagged messages."));
640 /* give visual indication that the next command is a tag- command */
641 mvaddstr (LINES - 1, 0, "tag-");
644 /* get the real command */
645 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
646 /* abort tag sequence */
647 CLEARLINE (LINES - 1);
651 else if (option (OPTAUTOTAG) && Context && Context->tagged)
654 if (op == OP_TAG_PREFIX_COND) {
656 mutt_error (_("No mailbox is open."));
661 if (!Context->tagged) {
664 while (UngetCount > 0) {
666 if (tmp.op == OP_END_COND)
669 mutt_message (_("Nothing to do."));
675 /* give visual indication that the next command is a tag- command */
676 mvaddstr (LINES - 1, 0, "tag-");
679 /* get the real command */
680 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
681 /* abort tag sequence */
682 CLEARLINE (LINES - 1);
690 if (menu->current < menu->max)
691 menu->oldcurrent = menu->current;
693 menu->oldcurrent = -1;
695 mutt_curs_set (1); /* fallback from the pager */
699 unset_option (OPTNEWS); /* for any case */
704 /* ----------------------------------------------------------------------
709 menu_bottom_page (menu);
712 menu_first_entry (menu);
715 menu_middle_page (menu);
721 menu_half_down (menu);
724 menu_next_line (menu);
727 menu_prev_line (menu);
730 menu_next_page (menu);
733 menu_prev_page (menu);
736 menu_last_entry (menu);
739 menu_top_page (menu);
742 menu_current_top (menu);
744 case OP_CURRENT_MIDDLE:
745 menu_current_middle (menu);
747 case OP_CURRENT_BOTTOM:
748 menu_current_bottom (menu);
755 if (Context->magic == M_NNTP) {
758 if (op == OP_GET_MESSAGE) {
760 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0)
765 LIST *ref = CURHDR->env->references;
768 mutt_error (_("Article has no parent reference!"));
772 strfcpy (buf, ref->data, sizeof (buf));
774 if (!Context->id_hash)
775 Context->id_hash = mutt_make_id_hash (Context);
776 if ((h = hash_find (Context->id_hash, buf))) {
777 if (h->virtual != -1) {
778 menu->current = h->virtual;
779 menu->redraw = REDRAW_MOTION_RESYNCH;
781 else if (h->collapsed) {
782 mutt_uncollapse_thread (Context, h);
783 mutt_set_virtual (Context);
784 menu->current = h->virtual;
785 menu->redraw = REDRAW_MOTION_RESYNCH;
788 mutt_error (_("Message not visible in limited view."));
791 if (nntp_check_msgid (Context, buf) == 0) {
792 h = Context->hdrs[Context->msgcount - 1];
793 mutt_sort_headers (Context, 0);
794 menu->current = h->virtual;
795 menu->redraw = REDRAW_FULL;
798 mutt_error (_("Article %s not found on server"), buf);
803 case OP_GET_CHILDREN:
804 case OP_RECONSTRUCT_THREAD:
806 if (Context->magic == M_NNTP) {
808 int old = CURHDR->index, i;
810 if (!CURHDR->env->message_id) {
811 mutt_error (_("No Message-Id. Unable to perform operation"));
816 if (!Context->id_hash)
817 Context->id_hash = mutt_make_id_hash (Context);
818 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
820 if (op == OP_RECONSTRUCT_THREAD) {
821 LIST *ref = CURHDR->env->references;
824 nntp_check_msgid (Context, ref->data);
825 /* the last msgid in References is the root message */
827 strfcpy (buf, ref->data, sizeof (buf));
831 mutt_message (_("Check for children of message..."));
833 if (nntp_check_children (Context, buf) == 0) {
834 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
835 h = hash_find (Context->id_hash, buf);
836 /* if the root message was retrieved, move to it */
838 menu->current = h->virtual;
839 else /* try to restore old position */
840 for (i = 0; i < Context->msgcount; i++)
841 if (Context->hdrs[i]->index == old) {
842 menu->current = Context->hdrs[i]->virtual;
843 /* As an added courtesy, recenter the menu
844 * with the current entry at the middle of the screen */
845 menu_check_recenter (menu);
846 menu_current_middle (menu);
849 menu->redraw = REDRAW_FULL;
859 if (isdigit (LastKey))
860 mutt_ungetch (LastKey, 0);
862 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
866 if (!isdigit ((unsigned char) buf[0])) {
867 mutt_error (_("Argument must be a message number."));
873 if (i > 0 && i <= Context->msgcount) {
874 for (j = i - 1; j < Context->msgcount; j++) {
875 if (Context->hdrs[j]->virtual != -1)
878 if (j >= Context->msgcount) {
879 for (j = i - 2; j >= 0; j--) {
880 if (Context->hdrs[j]->virtual != -1)
886 menu->current = Context->hdrs[j]->virtual;
887 if (menu->menu == MENU_PAGER) {
888 op = OP_DISPLAY_MESSAGE;
892 menu->redraw = REDRAW_MOTION;
895 mutt_error (_("That message is not visible."));
898 mutt_error (_("Invalid message number."));
902 /* --------------------------------------------------------------------
903 * `index' specific commands
906 case OP_MAIN_DELETE_PATTERN:
912 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
915 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
916 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
920 case OP_MAIN_FETCH_MAIL:
924 menu->redraw = REDRAW_FULL;
930 mutt_help (MENU_MAIN);
931 menu->redraw = REDRAW_FULL;
934 case OP_MAIN_SHOW_LIMIT:
936 if (!Context->pattern)
937 mutt_message (_("No limit pattern is in effect."));
942 /* i18n: ask for a limit to apply */
943 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
944 mutt_message ("%s", buf);
952 menu->oldcurrent = (Context->vcount && menu->current >= 0
954 Context->vcount) ? CURHDR->index : -1;
955 if (op == OP_TOGGLE_READ) {
956 char buf[LONG_STRING];
958 if (!Context->pattern
959 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
960 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
961 Context->pattern ? Context->pattern : ".*");
962 set_option (OPTHIDEREAD);
965 strfcpy (buf, Context->pattern + 8, sizeof (buf));
966 if (!*buf || strncmp (buf, ".*", 2) == 0)
967 snprintf (buf, sizeof (buf), "~A");
968 unset_option (OPTHIDEREAD);
970 FREE (&Context->pattern);
971 Context->pattern = safe_strdup (buf);
973 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
974 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
976 if (menu->oldcurrent >= 0) {
977 /* try to find what used to be the current message */
979 for (i = 0; i < Context->vcount; i++)
980 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
984 if (menu->current < 0)
989 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
990 if ((Sort & SORT_MASK) == SORT_THREADS)
991 mutt_draw_tree (Context);
992 menu->redraw = REDRAW_FULL;
1004 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1007 oldcount = Context ? Context->msgcount : 0;
1010 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1013 if (check == M_NEW_MAIL || check == M_REOPENED)
1014 update_index (menu, Context, check, oldcount, index_hint);
1016 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1017 set_option (OPTSEARCHINVALID);
1024 clearok (stdscr, TRUE);
1025 menu->redraw = REDRAW_FULL;
1029 case OP_SEARCH_REVERSE:
1030 case OP_SEARCH_NEXT:
1031 case OP_SEARCH_OPPOSITE:
1035 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1036 menu->current = menu->oldcurrent;
1038 menu->redraw = REDRAW_MOTION;
1042 case OP_SORT_REVERSE:
1044 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1045 if (Context && Context->msgcount) {
1046 resort_index (menu);
1047 set_option (OPTSEARCHINVALID);
1056 if (tag && !option (OPTAUTOTAG)) {
1057 for (j = 0; j < Context->vcount; j++)
1058 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1059 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1062 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1063 Context->last_tag = CURHDR->tagged ? CURHDR :
1064 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1065 ? NULL : Context->last_tag);
1066 menu->redraw = REDRAW_STATUS;
1067 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1069 menu->redraw |= REDRAW_MOTION_RESYNCH;
1072 menu->redraw |= REDRAW_CURRENT;
1076 case OP_MAIN_TAG_PATTERN:
1080 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1081 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1084 case OP_MAIN_UNDELETE_PATTERN:
1090 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1092 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1094 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1097 case OP_MAIN_UNTAG_PATTERN:
1101 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1102 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1105 /* --------------------------------------------------------------------
1106 * The following operations can be performed inside of the pager.
1110 case OP_MAIN_IMAP_FETCH:
1111 if (Context->magic == M_IMAP)
1112 imap_check_mailbox (Context, &index_hint, 1);
1116 case OP_MAIN_SYNC_FOLDER:
1118 if (Context && !Context->msgcount)
1125 int oldvcount = Context->vcount;
1126 int oldcount = Context->msgcount;
1130 /* calculate the number of messages _above_ the cursor,
1131 * so we can keep the cursor on the current message
1133 for (j = 0; j <= menu->current; j++) {
1134 if (Context->hdrs[Context->v2r[j]]->deleted)
1138 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1139 if (Context->vcount != oldvcount)
1140 menu->current -= dcount;
1141 set_option (OPTSEARCHINVALID);
1143 else if (check == M_NEW_MAIL || check == M_REOPENED)
1144 update_index (menu, Context, check, oldcount, index_hint);
1147 * do a sanity check even if mx_sync_mailbox failed.
1150 if (menu->current < 0 || menu->current >= Context->vcount)
1151 menu->current = ci_first_message ();
1154 /* check for a fatal error, or all messages deleted */
1158 /* if we were in the pager, redisplay the message */
1159 if (menu->menu == MENU_PAGER) {
1160 op = OP_DISPLAY_MESSAGE;
1164 menu->redraw = REDRAW_FULL;
1167 case OP_SIDEBAR_OPEN:
1168 case OP_MAIN_CHANGE_FOLDER:
1169 case OP_MAIN_CHANGE_FOLDER_READONLY:
1171 case OP_MAIN_CHANGE_GROUP:
1172 case OP_MAIN_CHANGE_GROUP_READONLY:
1174 if (attach_msg || option (OPTREADONLY) ||
1176 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1178 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1184 cp = _("Open mailbox in read-only mode");
1186 cp = _("Open mailbox");
1190 unset_option (OPTNEWS);
1191 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1192 set_option (OPTNEWS);
1193 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1196 cp = _("Open newsgroup in read-only mode");
1198 cp = _("Open newsgroup");
1204 if (Context && Context->path)
1205 strncpy (buf, Context->path, sizeof (buf));
1206 buffy_next (buf, sizeof (buf));
1209 if (op == OP_SIDEBAR_OPEN) {
1210 strncpy (buf, NONULL(sidebar_get_current ()), sizeof (buf));
1212 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1216 CLEARLINE (LINES - 1);
1221 if (option (OPTNEWS)) {
1222 unset_option (OPTNEWS);
1223 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1227 mutt_expand_path (buf, sizeof (buf));
1228 sidebar_set_current (buf);
1229 if (mx_get_magic (buf) <= 0) {
1230 mutt_error (_("%s is not a mailbox."), buf);
1233 str_replace (&CurrentFolder, buf);
1238 #ifdef USE_COMPRESSED
1239 if (Context->compressinfo && Context->realpath)
1240 str_replace (&LastFolder, Context->realpath);
1244 str_replace (&LastFolder, Context->path);
1245 oldcount = Context ? Context->msgcount : 0;
1247 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1248 if (check == M_NEW_MAIL || check == M_REOPENED)
1249 update_index (menu, Context, check, oldcount, index_hint);
1251 set_option (OPTSEARCHINVALID);
1252 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1260 /* Set CurrentMenu to MENU_MAIN before executing any folder
1261 * hooks so that all the index menu functions are available to
1265 CurrentMenu = MENU_MAIN;
1266 mutt_folder_hook (buf);
1268 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1269 menu->current = ci_first_message ();
1275 /* buffy_check() must be done with mail-reader mode! */
1276 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1278 && (Context->magic ==
1279 M_NNTP)) ? IndexNewsHelp :
1282 mutt_clear_error ();
1283 buffy_check (1); /* force the buffy check after we have changed
1285 menu->redraw = REDRAW_FULL;
1286 set_option (OPTSEARCHINVALID);
1289 case OP_DISPLAY_MESSAGE:
1290 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1295 * toggle the weeding of headers so that a user can press the key
1296 * again while reading the message.
1298 if (op == OP_DISPLAY_HEADERS)
1299 toggle_option (OPTWEED);
1301 unset_option (OPTNEEDRESORT);
1303 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1304 mutt_uncollapse_thread (Context, CURHDR);
1305 mutt_set_virtual (Context);
1306 if (option (OPTUNCOLLAPSEJUMP))
1307 menu->current = mutt_thread_next_unread (Context, CURHDR);
1310 if ((op = mutt_display_message (CURHDR)) == -1) {
1311 unset_option (OPTNEEDRESORT);
1315 menu->menu = MENU_PAGER;
1316 menu->oldcurrent = menu->current;
1322 if (menu->menu == MENU_MAIN && attach_msg) {
1327 if ((menu->menu == MENU_MAIN)
1328 && (query_quadoption (OPT_QUIT,
1329 _("Exit Mutt-ng without saving?")) == M_YES))
1332 mx_fastclose_mailbox (Context);
1344 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1345 /* if we were in the pager, redisplay the message */
1346 if (menu->menu == MENU_PAGER) {
1347 op = OP_DISPLAY_MESSAGE;
1351 menu->redraw = REDRAW_CURRENT;
1354 case OP_MAIN_BREAK_THREAD:
1360 if ((Sort & SORT_MASK) != SORT_THREADS)
1361 mutt_error (_("Threading is not enabled."));
1365 HEADER *oldcur = CURHDR;
1367 mutt_break_thread (CURHDR);
1368 mutt_sort_headers (Context, 1);
1369 menu->current = oldcur->virtual;
1372 Context->changed = 1;
1373 mutt_message _("Thread broken");
1375 if (menu->menu == MENU_PAGER) {
1376 op = OP_DISPLAY_MESSAGE;
1380 menu->redraw |= REDRAW_INDEX;
1384 case OP_MAIN_LINK_THREADS:
1390 if ((Sort & SORT_MASK) != SORT_THREADS)
1391 mutt_error (_("Threading is not enabled."));
1393 else if (!CURHDR->env->message_id)
1394 mutt_error (_("No Message-ID: header available to link thread"));
1396 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1397 mutt_error (_("First, please tag a message to be linked here"));
1400 HEADER *oldcur = CURHDR;
1402 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1404 mutt_sort_headers (Context, 1);
1405 menu->current = oldcur->virtual;
1407 Context->changed = 1;
1408 mutt_message _("Threads linked");
1411 mutt_error (_("No thread linked"));
1414 if (menu->menu == MENU_PAGER) {
1415 op = OP_DISPLAY_MESSAGE;
1419 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1422 case OP_MAIN_NEXT_UNDELETED:
1426 if (menu->current >= Context->vcount - 1) {
1427 if (menu->menu == MENU_MAIN)
1428 mutt_error (_("You are on the last message."));
1432 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1433 menu->current = menu->oldcurrent;
1434 if (menu->menu == MENU_MAIN)
1435 mutt_error (_("No undeleted messages."));
1437 else if (menu->menu == MENU_PAGER) {
1438 op = OP_DISPLAY_MESSAGE;
1442 menu->redraw = REDRAW_MOTION;
1449 if (menu->current >= Context->vcount - 1) {
1450 if (menu->menu == MENU_MAIN)
1451 mutt_error (_("You are on the last message."));
1456 if (menu->menu == MENU_PAGER) {
1457 op = OP_DISPLAY_MESSAGE;
1461 menu->redraw = REDRAW_MOTION;
1464 case OP_MAIN_PREV_UNDELETED:
1468 if (menu->current < 1) {
1469 mutt_error (_("You are on the first message."));
1473 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1474 menu->current = menu->oldcurrent;
1475 if (menu->menu == MENU_MAIN)
1476 mutt_error (_("No undeleted messages."));
1478 else if (menu->menu == MENU_PAGER) {
1479 op = OP_DISPLAY_MESSAGE;
1483 menu->redraw = REDRAW_MOTION;
1490 if (menu->current < 1) {
1491 if (menu->menu == MENU_MAIN)
1492 mutt_error (_("You are on the first message."));
1497 if (menu->menu == MENU_PAGER) {
1498 op = OP_DISPLAY_MESSAGE;
1502 menu->redraw = REDRAW_MOTION;
1505 case OP_DECRYPT_COPY:
1506 case OP_DECRYPT_SAVE:
1510 case OP_COPY_MESSAGE:
1512 case OP_DECODE_COPY:
1513 case OP_DECODE_SAVE:
1516 if (mutt_save_message (tag ? NULL : CURHDR,
1517 (op == OP_DECRYPT_SAVE) ||
1518 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1519 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1520 (op == OP_DECRYPT_SAVE)
1521 || (op == OP_DECRYPT_COPY)
1522 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1529 menu->redraw |= REDRAW_INDEX;
1530 else if (option (OPTRESOLVE)) {
1531 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1532 menu->current = menu->oldcurrent;
1533 menu->redraw |= REDRAW_CURRENT;
1536 menu->redraw |= REDRAW_MOTION_RESYNCH;
1539 menu->redraw |= REDRAW_CURRENT;
1543 case OP_MAIN_NEXT_NEW:
1544 case OP_MAIN_NEXT_UNREAD:
1545 case OP_MAIN_PREV_NEW:
1546 case OP_MAIN_PREV_UNREAD:
1547 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1548 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1551 int first_unread = -1;
1559 for (j = 0; j != Context->vcount; j++) {
1560 #define CURHDRi Context->hdrs[Context->v2r[i]]
1561 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1562 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1564 if (i > Context->vcount - 1) {
1565 mutt_message _("Search wrapped to top.");
1573 mutt_message _("Search wrapped to bottom.");
1575 i = Context->vcount - 1;
1579 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1580 if (UNREAD (CURHDRi) && first_unread == -1)
1582 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1585 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1586 if (first_unread == -1)
1588 if ((!CURHDRi->old) && first_new == -1)
1592 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1595 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1596 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1597 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1602 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1603 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1604 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1606 menu->current = first_new;
1607 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1608 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1609 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1610 && first_unread != -1)
1611 menu->current = first_unread;
1613 if (menu->current == -1) {
1614 menu->current = menu->oldcurrent;
1615 mutt_error ("%s%s.",
1616 (op == OP_MAIN_NEXT_NEW
1618 OP_MAIN_PREV_NEW) ? _("No new messages") :
1619 _("No unread messages"),
1620 Context->pattern ? _(" in this limited view") : "");
1622 else if (menu->menu == MENU_PAGER) {
1623 op = OP_DISPLAY_MESSAGE;
1627 menu->redraw = REDRAW_MOTION;
1630 case OP_FLAG_MESSAGE:
1636 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1639 for (j = 0; j < Context->vcount; j++) {
1640 if (Context->hdrs[Context->v2r[j]]->tagged)
1641 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1642 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1645 menu->redraw |= REDRAW_INDEX;
1648 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1649 if (option (OPTRESOLVE)) {
1650 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1651 menu->current = menu->oldcurrent;
1652 menu->redraw = REDRAW_CURRENT;
1655 menu->redraw = REDRAW_MOTION_RESYNCH;
1658 menu->redraw = REDRAW_CURRENT;
1660 menu->redraw |= REDRAW_STATUS;
1669 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1672 for (j = 0; j < Context->vcount; j++) {
1673 if (Context->hdrs[Context->v2r[j]]->tagged) {
1674 if (Context->hdrs[Context->v2r[j]]->read ||
1675 Context->hdrs[Context->v2r[j]]->old)
1676 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1679 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1683 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1686 if (CURHDR->read || CURHDR->old)
1687 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1689 mutt_set_flag (Context, CURHDR, M_READ, 1);
1691 if (option (OPTRESOLVE)) {
1692 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1693 menu->current = menu->oldcurrent;
1694 menu->redraw = REDRAW_CURRENT;
1697 menu->redraw = REDRAW_MOTION_RESYNCH;
1700 menu->redraw = REDRAW_CURRENT;
1701 menu->redraw |= REDRAW_STATUS;
1705 case OP_TOGGLE_WRITE:
1708 if (mx_toggle_write (Context) == 0)
1709 menu->redraw |= REDRAW_STATUS;
1712 case OP_MAIN_NEXT_THREAD:
1713 case OP_MAIN_NEXT_SUBTHREAD:
1714 case OP_MAIN_PREV_THREAD:
1715 case OP_MAIN_PREV_SUBTHREAD:
1720 case OP_MAIN_NEXT_THREAD:
1721 menu->current = mutt_next_thread (CURHDR);
1724 case OP_MAIN_NEXT_SUBTHREAD:
1725 menu->current = mutt_next_subthread (CURHDR);
1728 case OP_MAIN_PREV_THREAD:
1729 menu->current = mutt_previous_thread (CURHDR);
1732 case OP_MAIN_PREV_SUBTHREAD:
1733 menu->current = mutt_previous_subthread (CURHDR);
1737 if (menu->current < 0) {
1738 menu->current = menu->oldcurrent;
1739 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1740 mutt_error (_("No more threads."));
1743 mutt_error (_("You are on the first thread."));
1745 else if (menu->menu == MENU_PAGER) {
1746 op = OP_DISPLAY_MESSAGE;
1750 menu->redraw = REDRAW_MOTION;
1753 case OP_MAIN_PARENT_MESSAGE:
1758 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1759 menu->current = menu->oldcurrent;
1761 else if (menu->menu == MENU_PAGER) {
1762 op = OP_DISPLAY_MESSAGE;
1766 menu->redraw = REDRAW_MOTION;
1769 case OP_MAIN_SET_FLAG:
1770 case OP_MAIN_CLEAR_FLAG:
1776 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1778 menu->redraw = REDRAW_STATUS;
1780 menu->redraw |= REDRAW_INDEX;
1781 else if (option (OPTRESOLVE)) {
1782 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1783 menu->current = menu->oldcurrent;
1784 menu->redraw |= REDRAW_CURRENT;
1787 menu->redraw |= REDRAW_MOTION_RESYNCH;
1790 menu->redraw |= REDRAW_CURRENT;
1794 case OP_MAIN_COLLAPSE_THREAD:
1798 if ((Sort & SORT_MASK) != SORT_THREADS) {
1799 mutt_error (_("Threading is not enabled."));
1804 if (CURHDR->collapsed) {
1805 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1806 mutt_set_virtual (Context);
1807 if (option (OPTUNCOLLAPSEJUMP))
1808 menu->current = mutt_thread_next_unread (Context, CURHDR);
1810 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1811 menu->current = mutt_collapse_thread (Context, CURHDR);
1812 mutt_set_virtual (Context);
1815 mutt_error (_("Thread contains unread messages."));
1820 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1824 case OP_MAIN_COLLAPSE_ALL:
1828 if ((Sort & SORT_MASK) != SORT_THREADS) {
1829 mutt_error (_("Threading is not enabled."));
1836 THREAD *thread, *top;
1839 if (CURHDR->collapsed)
1840 final = mutt_uncollapse_thread (Context, CURHDR);
1841 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1842 final = mutt_collapse_thread (Context, CURHDR);
1844 final = CURHDR->virtual;
1846 base = Context->hdrs[Context->v2r[final]];
1848 top = Context->tree;
1849 Context->collapsed = !Context->collapsed;
1850 while ((thread = top) != NULL) {
1851 while (!thread->message)
1852 thread = thread->child;
1853 h = thread->message;
1855 if (h->collapsed != Context->collapsed) {
1857 mutt_uncollapse_thread (Context, h);
1858 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1859 mutt_collapse_thread (Context, h);
1864 mutt_set_virtual (Context);
1865 for (j = 0; j < Context->vcount; j++) {
1866 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1872 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1876 /* --------------------------------------------------------------------
1877 * These functions are invoked directly from the internal-pager
1880 case OP_BOUNCE_MESSAGE:
1885 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1888 case OP_CREATE_ALIAS:
1890 mutt_create_alias (Context
1891 && Context->vcount ? CURHDR->env : NULL, NULL);
1892 MAYBE_REDRAW (menu->redraw);
1893 menu->redraw |= REDRAW_CURRENT;
1898 mutt_query_menu (NULL, 0);
1899 MAYBE_REDRAW (menu->redraw);
1902 case OP_PURGE_MESSAGE:
1909 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1912 mutt_tag_set_flag (M_DELETE, 1);
1913 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1914 if (option (OPTDELETEUNTAG))
1915 mutt_tag_set_flag (M_TAG, 0);
1916 menu->redraw = REDRAW_INDEX;
1919 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1920 mutt_set_flag (Context, CURHDR, M_PURGED,
1921 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1922 if (option (OPTDELETEUNTAG))
1923 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1924 if (option (OPTRESOLVE)) {
1925 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1926 menu->current = menu->oldcurrent;
1927 menu->redraw = REDRAW_CURRENT;
1929 else if (menu->menu == MENU_PAGER) {
1930 op = OP_DISPLAY_MESSAGE;
1934 menu->redraw |= REDRAW_MOTION_RESYNCH;
1937 menu->redraw = REDRAW_CURRENT;
1939 menu->redraw |= REDRAW_STATUS;
1942 case OP_DELETE_THREAD:
1943 case OP_DELETE_SUBTHREAD:
1949 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1951 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1952 op == OP_DELETE_THREAD ? 0 : 1);
1955 if (option (OPTDELETEUNTAG))
1956 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1957 op == OP_DELETE_THREAD ? 0 : 1);
1958 if (option (OPTRESOLVE))
1959 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1960 menu->current = menu->oldcurrent;
1961 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1967 if (Context && Context->magic == M_NNTP) {
1968 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1969 ((NNTP_DATA *) Context->data)->group))
1970 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1975 case OP_DISPLAY_ADDRESS:
1979 mutt_display_address (CURHDR->env);
1982 case OP_ENTER_COMMAND:
1984 CurrentMenu = MENU_MAIN;
1985 mutt_enter_command ();
1986 mutt_check_rescore (Context);
1987 if (option (OPTFORCEREDRAWINDEX))
1988 menu->redraw = REDRAW_FULL;
1989 unset_option (OPTFORCEREDRAWINDEX);
1990 unset_option (OPTFORCEREDRAWPAGER);
1993 case OP_EDIT_MESSAGE:
2000 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
2002 if (option (OPTPGPAUTODEC)
2003 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2004 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2005 mutt_edit_message (Context, tag ? NULL : CURHDR);
2006 menu->redraw = REDRAW_FULL;
2010 case OP_FORWARD_MESSAGE:
2015 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2016 menu->redraw = REDRAW_FULL;
2020 case OP_FORGET_PASSPHRASE:
2021 crypt_forget_passphrase ();
2024 case OP_GROUP_REPLY:
2029 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2030 tag ? NULL : CURHDR);
2031 menu->redraw = REDRAW_FULL;
2039 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2040 tag ? NULL : CURHDR);
2041 menu->redraw = REDRAW_FULL;
2047 ci_send_message (0, NULL, NULL, Context, NULL);
2048 menu->redraw = REDRAW_FULL;
2052 if (!(WithCrypto & APPLICATION_PGP))
2055 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2056 menu->redraw = REDRAW_FULL;
2060 case OP_EXTRACT_KEYS:
2065 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2066 menu->redraw = REDRAW_FULL;
2070 case OP_CHECK_TRADITIONAL:
2071 if (!(WithCrypto & APPLICATION_PGP))
2075 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2076 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2078 if (menu->menu == MENU_PAGER) {
2079 op = OP_DISPLAY_MESSAGE;
2088 mutt_pipe_message (tag ? NULL : CURHDR);
2089 MAYBE_REDRAW (menu->redraw);
2096 mutt_print_message (tag ? NULL : CURHDR);
2099 case OP_MAIN_READ_THREAD:
2100 case OP_MAIN_READ_SUBTHREAD:
2106 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2108 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2109 op == OP_MAIN_READ_THREAD ? 0 : 1);
2112 if (option (OPTRESOLVE)) {
2113 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2114 mutt_next_thread (CURHDR) :
2115 mutt_next_subthread (CURHDR))) == -1)
2116 menu->current = menu->oldcurrent;
2118 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2122 case OP_RECALL_MESSAGE:
2125 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2126 menu->redraw = REDRAW_FULL;
2136 for (j = 0; j < Context->vcount; j++) {
2137 if (Context->hdrs[Context->v2r[j]]->tagged)
2138 mutt_resend_message (NULL, Context,
2139 Context->hdrs[Context->v2r[j]]);
2143 mutt_resend_message (NULL, Context, CURHDR);
2145 menu->redraw = REDRAW_FULL;
2151 case OP_FORWARD_TO_GROUP:
2154 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2155 Context && Context->msgcount == 0) {
2156 mutt_error (_("There are no messages."));
2159 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2160 safe_strcasecmp (CURHDR->env->followup_to, "poster") ||
2161 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2162 _("Reply by mail as poster prefers?")) !=
2164 if (Context && Context->magic == M_NNTP
2165 && !((NNTP_DATA *) Context->data)->allowed
2166 && query_quadoption (OPT_TOMODERATED,
2168 ("Posting to this group not allowed, may be moderated. Continue?"))
2172 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2175 if (op == OP_FOLLOWUP)
2176 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2177 tag ? NULL : CURHDR);
2179 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2180 tag ? NULL : CURHDR);
2182 menu->redraw = REDRAW_FULL;
2192 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2193 menu->redraw = REDRAW_FULL;
2196 case OP_SHELL_ESCAPE:
2198 mutt_shell_escape ();
2199 MAYBE_REDRAW (menu->redraw);
2203 case OP_TAG_SUBTHREAD:
2207 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2208 op == OP_TAG_THREAD ? 0 : 1);
2211 if (option (OPTRESOLVE)) {
2212 menu->current = mutt_next_thread (CURHDR);
2214 if (menu->current == -1)
2215 menu->current = menu->oldcurrent;
2217 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2227 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2230 mutt_tag_set_flag (M_DELETE, 0);
2231 mutt_tag_set_flag (M_PURGED, 0);
2232 menu->redraw = REDRAW_INDEX;
2235 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2236 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2237 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2239 menu->redraw = REDRAW_MOTION_RESYNCH;
2242 menu->redraw = REDRAW_CURRENT;
2244 menu->redraw |= REDRAW_STATUS;
2247 case OP_UNDELETE_THREAD:
2248 case OP_UNDELETE_SUBTHREAD:
2254 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2256 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2257 op == OP_UNDELETE_THREAD ? 0 : 1)
2258 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2259 op == OP_UNDELETE_THREAD ? 0 : 1);
2262 if (option (OPTRESOLVE)) {
2263 if (op == OP_UNDELETE_THREAD)
2264 menu->current = mutt_next_thread (CURHDR);
2266 menu->current = mutt_next_subthread (CURHDR);
2268 if (menu->current == -1)
2269 menu->current = menu->oldcurrent;
2271 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2281 menu->redraw = REDRAW_FULL;
2284 case OP_VIEW_ATTACHMENTS:
2287 mutt_view_attachments (CURHDR);
2288 if (CURHDR->attach_del)
2289 Context->changed = 1;
2290 menu->redraw = REDRAW_FULL;
2300 case OP_SIDEBAR_SCROLL_UP:
2301 case OP_SIDEBAR_SCROLL_DOWN:
2302 case OP_SIDEBAR_NEXT:
2303 case OP_SIDEBAR_PREV:
2304 case OP_SIDEBAR_NEXT_NEW:
2305 case OP_SIDEBAR_PREV_NEW:
2306 sidebar_scroll (op, menu->menu);
2309 if (menu->menu == MENU_MAIN)
2310 km_error_key (MENU_MAIN);
2313 if (menu->menu == MENU_PAGER) {
2314 menu->menu = MENU_MAIN;
2315 menu->redraw = REDRAW_FULL;
2317 set_option (OPTWEED); /* turn header weeding back on. */
2326 /* Close all open IMAP connections */
2331 /* Close all open NNTP connections */
2336 mutt_menuDestroy (&menu);
2340 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2347 for (color = ColorIndexList; color; color = color->next)
2348 if (mutt_pattern_exec
2349 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2350 curhdr->pair = color->pair;
2353 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];