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);
595 else if (option (OPTBRAILLEFRIENDLY))
596 move (menu->current - menu->top + menu->offset, 0);
598 move (menu->current - menu->top + menu->offset, COLS - 1);
601 op = km_dokey (MENU_MAIN);
603 debug_print (4, ("Got op %d\n", op));
605 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
608 mutt_resize_screen ();
609 menu->redraw = REDRAW_FULL;
610 menu->menu = MENU_MAIN;
612 menu->top = 0; /* so we scroll the right amount */
614 * force a real complete redraw. clrtobot() doesn't seem to be able
615 * to handle every case without this.
617 clearok (stdscr, TRUE);
623 continue; /* either user abort or timeout */
627 /* special handling for the tag-prefix function */
628 if (op == OP_TAG_PREFIX) {
630 mutt_error (_("No mailbox is open."));
635 if (!Context->tagged) {
636 mutt_error (_("No tagged messages."));
642 /* give visual indication that the next command is a tag- command */
643 mvaddstr (LINES - 1, 0, "tag-");
646 /* get the real command */
647 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
648 /* abort tag sequence */
649 CLEARLINE (LINES - 1);
653 else if (option (OPTAUTOTAG) && Context && Context->tagged)
656 if (op == OP_TAG_PREFIX_COND) {
658 mutt_error (_("No mailbox is open."));
663 if (!Context->tagged) {
666 while (UngetCount > 0) {
668 if (tmp.op == OP_END_COND)
671 mutt_message (_("Nothing to do."));
677 /* give visual indication that the next command is a tag- command */
678 mvaddstr (LINES - 1, 0, "tag-");
681 /* get the real command */
682 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
683 /* abort tag sequence */
684 CLEARLINE (LINES - 1);
692 if (menu->current < menu->max)
693 menu->oldcurrent = menu->current;
695 menu->oldcurrent = -1;
697 mutt_curs_set (1); /* fallback from the pager */
701 unset_option (OPTNEWS); /* for any case */
706 /* ----------------------------------------------------------------------
711 menu_bottom_page (menu);
714 menu_first_entry (menu);
717 menu_middle_page (menu);
723 menu_half_down (menu);
726 menu_next_line (menu);
729 menu_prev_line (menu);
732 menu_next_page (menu);
735 menu_prev_page (menu);
738 menu_last_entry (menu);
741 menu_top_page (menu);
744 menu_current_top (menu);
746 case OP_CURRENT_MIDDLE:
747 menu_current_middle (menu);
749 case OP_CURRENT_BOTTOM:
750 menu_current_bottom (menu);
757 if (Context->magic == M_NNTP) {
760 if (op == OP_GET_MESSAGE) {
762 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0)
767 LIST *ref = CURHDR->env->references;
770 mutt_error (_("Article has no parent reference!"));
774 strfcpy (buf, ref->data, sizeof (buf));
776 if (!Context->id_hash)
777 Context->id_hash = mutt_make_id_hash (Context);
778 if ((h = hash_find (Context->id_hash, buf))) {
779 if (h->virtual != -1) {
780 menu->current = h->virtual;
781 menu->redraw = REDRAW_MOTION_RESYNCH;
783 else if (h->collapsed) {
784 mutt_uncollapse_thread (Context, h);
785 mutt_set_virtual (Context);
786 menu->current = h->virtual;
787 menu->redraw = REDRAW_MOTION_RESYNCH;
790 mutt_error (_("Message not visible in limited view."));
793 if (nntp_check_msgid (Context, buf) == 0) {
794 h = Context->hdrs[Context->msgcount - 1];
795 mutt_sort_headers (Context, 0);
796 menu->current = h->virtual;
797 menu->redraw = REDRAW_FULL;
800 mutt_error (_("Article %s not found on server"), buf);
805 case OP_GET_CHILDREN:
806 case OP_RECONSTRUCT_THREAD:
808 if (Context->magic == M_NNTP) {
810 int old = CURHDR->index, i;
812 if (!CURHDR->env->message_id) {
813 mutt_error (_("No Message-Id. Unable to perform operation"));
818 if (!Context->id_hash)
819 Context->id_hash = mutt_make_id_hash (Context);
820 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
822 if (op == OP_RECONSTRUCT_THREAD) {
823 LIST *ref = CURHDR->env->references;
826 nntp_check_msgid (Context, ref->data);
827 /* the last msgid in References is the root message */
829 strfcpy (buf, ref->data, sizeof (buf));
833 mutt_message (_("Check for children of message..."));
835 if (nntp_check_children (Context, buf) == 0) {
836 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
837 h = hash_find (Context->id_hash, buf);
838 /* if the root message was retrieved, move to it */
840 menu->current = h->virtual;
841 else /* try to restore old position */
842 for (i = 0; i < Context->msgcount; i++)
843 if (Context->hdrs[i]->index == old) {
844 menu->current = Context->hdrs[i]->virtual;
845 /* As an added courtesy, recenter the menu
846 * with the current entry at the middle of the screen */
847 menu_check_recenter (menu);
848 menu_current_middle (menu);
851 menu->redraw = REDRAW_FULL;
861 if (isdigit (LastKey))
862 mutt_ungetch (LastKey, 0);
864 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
868 if (!isdigit ((unsigned char) buf[0])) {
869 mutt_error (_("Argument must be a message number."));
875 if (i > 0 && i <= Context->msgcount) {
876 for (j = i - 1; j < Context->msgcount; j++) {
877 if (Context->hdrs[j]->virtual != -1)
880 if (j >= Context->msgcount) {
881 for (j = i - 2; j >= 0; j--) {
882 if (Context->hdrs[j]->virtual != -1)
888 menu->current = Context->hdrs[j]->virtual;
889 if (menu->menu == MENU_PAGER) {
890 op = OP_DISPLAY_MESSAGE;
894 menu->redraw = REDRAW_MOTION;
897 mutt_error (_("That message is not visible."));
900 mutt_error (_("Invalid message number."));
904 /* --------------------------------------------------------------------
905 * `index' specific commands
908 case OP_MAIN_DELETE_PATTERN:
914 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
917 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
918 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
922 case OP_MAIN_FETCH_MAIL:
926 menu->redraw = REDRAW_FULL;
932 mutt_help (MENU_MAIN);
933 menu->redraw = REDRAW_FULL;
936 case OP_MAIN_SHOW_LIMIT:
938 if (!Context->pattern)
939 mutt_message (_("No limit pattern is in effect."));
944 /* i18n: ask for a limit to apply */
945 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
946 mutt_message ("%s", buf);
954 menu->oldcurrent = (Context->vcount && menu->current >= 0
956 Context->vcount) ? CURHDR->index : -1;
957 if (op == OP_TOGGLE_READ) {
958 char buf[LONG_STRING];
960 if (!Context->pattern
961 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
962 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
963 Context->pattern ? Context->pattern : ".*");
964 set_option (OPTHIDEREAD);
967 strfcpy (buf, Context->pattern + 8, sizeof (buf));
968 if (!*buf || strncmp (buf, ".*", 2) == 0)
969 snprintf (buf, sizeof (buf), "~A");
970 unset_option (OPTHIDEREAD);
972 FREE (&Context->pattern);
973 Context->pattern = safe_strdup (buf);
975 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
976 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
978 if (menu->oldcurrent >= 0) {
979 /* try to find what used to be the current message */
981 for (i = 0; i < Context->vcount; i++)
982 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
986 if (menu->current < 0)
991 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
992 if ((Sort & SORT_MASK) == SORT_THREADS)
993 mutt_draw_tree (Context);
994 menu->redraw = REDRAW_FULL;
1006 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1009 oldcount = Context ? Context->msgcount : 0;
1012 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1015 if (check == M_NEW_MAIL || check == M_REOPENED)
1016 update_index (menu, Context, check, oldcount, index_hint);
1018 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1019 set_option (OPTSEARCHINVALID);
1026 clearok (stdscr, TRUE);
1027 menu->redraw = REDRAW_FULL;
1031 case OP_SEARCH_REVERSE:
1032 case OP_SEARCH_NEXT:
1033 case OP_SEARCH_OPPOSITE:
1037 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1038 menu->current = menu->oldcurrent;
1040 menu->redraw = REDRAW_MOTION;
1044 case OP_SORT_REVERSE:
1046 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1047 if (Context && Context->msgcount) {
1048 resort_index (menu);
1049 set_option (OPTSEARCHINVALID);
1058 if (tag && !option (OPTAUTOTAG)) {
1059 for (j = 0; j < Context->vcount; j++)
1060 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1061 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1064 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1065 Context->last_tag = CURHDR->tagged ? CURHDR :
1066 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1067 ? NULL : Context->last_tag);
1068 menu->redraw = REDRAW_STATUS;
1069 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1071 menu->redraw |= REDRAW_MOTION_RESYNCH;
1074 menu->redraw |= REDRAW_CURRENT;
1078 case OP_MAIN_TAG_PATTERN:
1082 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1083 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1086 case OP_MAIN_UNDELETE_PATTERN:
1092 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1094 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1096 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1099 case OP_MAIN_UNTAG_PATTERN:
1103 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1104 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1107 /* --------------------------------------------------------------------
1108 * The following operations can be performed inside of the pager.
1112 case OP_MAIN_IMAP_FETCH:
1113 if (Context->magic == M_IMAP)
1114 imap_check_mailbox (Context, &index_hint, 1);
1118 case OP_MAIN_SYNC_FOLDER:
1120 if (Context && !Context->msgcount)
1127 int oldvcount = Context->vcount;
1128 int oldcount = Context->msgcount;
1132 /* calculate the number of messages _above_ the cursor,
1133 * so we can keep the cursor on the current message
1135 for (j = 0; j <= menu->current; j++) {
1136 if (Context->hdrs[Context->v2r[j]]->deleted)
1140 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1141 if (Context->vcount != oldvcount)
1142 menu->current -= dcount;
1143 set_option (OPTSEARCHINVALID);
1145 else if (check == M_NEW_MAIL || check == M_REOPENED)
1146 update_index (menu, Context, check, oldcount, index_hint);
1149 * do a sanity check even if mx_sync_mailbox failed.
1152 if (menu->current < 0 || menu->current >= Context->vcount)
1153 menu->current = ci_first_message ();
1156 /* check for a fatal error, or all messages deleted */
1160 /* if we were in the pager, redisplay the message */
1161 if (menu->menu == MENU_PAGER) {
1162 op = OP_DISPLAY_MESSAGE;
1166 menu->redraw = REDRAW_FULL;
1169 case OP_SIDEBAR_OPEN:
1170 case OP_MAIN_CHANGE_FOLDER:
1171 case OP_MAIN_CHANGE_FOLDER_READONLY:
1173 case OP_MAIN_CHANGE_GROUP:
1174 case OP_MAIN_CHANGE_GROUP_READONLY:
1176 if (attach_msg || option (OPTREADONLY) ||
1178 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1180 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1186 cp = _("Open mailbox in read-only mode");
1188 cp = _("Open mailbox");
1192 unset_option (OPTNEWS);
1193 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1194 set_option (OPTNEWS);
1195 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1198 cp = _("Open newsgroup in read-only mode");
1200 cp = _("Open newsgroup");
1206 if (Context && Context->path)
1207 strncpy (buf, Context->path, sizeof (buf));
1208 buffy_next (buf, sizeof (buf));
1211 if (op == OP_SIDEBAR_OPEN) {
1212 strncpy (buf, NONULL(sidebar_get_current ()), sizeof (buf));
1214 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1218 CLEARLINE (LINES - 1);
1223 if (option (OPTNEWS)) {
1224 unset_option (OPTNEWS);
1225 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1229 mutt_expand_path (buf, sizeof (buf));
1230 sidebar_set_current (buf);
1231 if (mx_get_magic (buf) <= 0) {
1232 mutt_error (_("%s is not a mailbox."), buf);
1235 str_replace (&CurrentFolder, buf);
1240 #ifdef USE_COMPRESSED
1241 if (Context->compressinfo && Context->realpath)
1242 str_replace (&LastFolder, Context->realpath);
1246 str_replace (&LastFolder, Context->path);
1247 oldcount = Context ? Context->msgcount : 0;
1249 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1250 if (check == M_NEW_MAIL || check == M_REOPENED)
1251 update_index (menu, Context, check, oldcount, index_hint);
1253 set_option (OPTSEARCHINVALID);
1254 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1262 /* Set CurrentMenu to MENU_MAIN before executing any folder
1263 * hooks so that all the index menu functions are available to
1267 CurrentMenu = MENU_MAIN;
1268 mutt_folder_hook (buf);
1270 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1271 menu->current = ci_first_message ();
1277 /* buffy_check() must be done with mail-reader mode! */
1278 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1280 && (Context->magic ==
1281 M_NNTP)) ? IndexNewsHelp :
1284 mutt_clear_error ();
1285 buffy_check (1); /* force the buffy check after we have changed
1287 menu->redraw = REDRAW_FULL;
1288 set_option (OPTSEARCHINVALID);
1291 case OP_DISPLAY_MESSAGE:
1292 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1297 * toggle the weeding of headers so that a user can press the key
1298 * again while reading the message.
1300 if (op == OP_DISPLAY_HEADERS)
1301 toggle_option (OPTWEED);
1303 unset_option (OPTNEEDRESORT);
1305 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1306 mutt_uncollapse_thread (Context, CURHDR);
1307 mutt_set_virtual (Context);
1308 if (option (OPTUNCOLLAPSEJUMP))
1309 menu->current = mutt_thread_next_unread (Context, CURHDR);
1312 if ((op = mutt_display_message (CURHDR)) == -1) {
1313 unset_option (OPTNEEDRESORT);
1317 menu->menu = MENU_PAGER;
1318 menu->oldcurrent = menu->current;
1324 if (menu->menu == MENU_MAIN && attach_msg) {
1329 if ((menu->menu == MENU_MAIN)
1330 && (query_quadoption (OPT_QUIT,
1331 _("Exit Mutt-ng without saving?")) == M_YES))
1334 mx_fastclose_mailbox (Context);
1346 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1347 /* if we were in the pager, redisplay the message */
1348 if (menu->menu == MENU_PAGER) {
1349 op = OP_DISPLAY_MESSAGE;
1353 menu->redraw = REDRAW_CURRENT;
1356 case OP_MAIN_BREAK_THREAD:
1362 if ((Sort & SORT_MASK) != SORT_THREADS)
1363 mutt_error (_("Threading is not enabled."));
1367 HEADER *oldcur = CURHDR;
1369 mutt_break_thread (CURHDR);
1370 mutt_sort_headers (Context, 1);
1371 menu->current = oldcur->virtual;
1374 Context->changed = 1;
1375 mutt_message _("Thread broken");
1377 if (menu->menu == MENU_PAGER) {
1378 op = OP_DISPLAY_MESSAGE;
1382 menu->redraw |= REDRAW_INDEX;
1386 case OP_MAIN_LINK_THREADS:
1392 if ((Sort & SORT_MASK) != SORT_THREADS)
1393 mutt_error (_("Threading is not enabled."));
1395 else if (!CURHDR->env->message_id)
1396 mutt_error (_("No Message-ID: header available to link thread"));
1398 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1399 mutt_error (_("First, please tag a message to be linked here"));
1402 HEADER *oldcur = CURHDR;
1404 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1406 mutt_sort_headers (Context, 1);
1407 menu->current = oldcur->virtual;
1409 Context->changed = 1;
1410 mutt_message _("Threads linked");
1413 mutt_error (_("No thread linked"));
1416 if (menu->menu == MENU_PAGER) {
1417 op = OP_DISPLAY_MESSAGE;
1421 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1424 case OP_MAIN_NEXT_UNDELETED:
1428 if (menu->current >= Context->vcount - 1) {
1429 if (menu->menu == MENU_MAIN)
1430 mutt_error (_("You are on the last message."));
1434 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1435 menu->current = menu->oldcurrent;
1436 if (menu->menu == MENU_MAIN)
1437 mutt_error (_("No undeleted messages."));
1439 else if (menu->menu == MENU_PAGER) {
1440 op = OP_DISPLAY_MESSAGE;
1444 menu->redraw = REDRAW_MOTION;
1451 if (menu->current >= Context->vcount - 1) {
1452 if (menu->menu == MENU_MAIN)
1453 mutt_error (_("You are on the last message."));
1458 if (menu->menu == MENU_PAGER) {
1459 op = OP_DISPLAY_MESSAGE;
1463 menu->redraw = REDRAW_MOTION;
1466 case OP_MAIN_PREV_UNDELETED:
1470 if (menu->current < 1) {
1471 mutt_error (_("You are on the first message."));
1475 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1476 menu->current = menu->oldcurrent;
1477 if (menu->menu == MENU_MAIN)
1478 mutt_error (_("No undeleted messages."));
1480 else if (menu->menu == MENU_PAGER) {
1481 op = OP_DISPLAY_MESSAGE;
1485 menu->redraw = REDRAW_MOTION;
1492 if (menu->current < 1) {
1493 if (menu->menu == MENU_MAIN)
1494 mutt_error (_("You are on the first message."));
1499 if (menu->menu == MENU_PAGER) {
1500 op = OP_DISPLAY_MESSAGE;
1504 menu->redraw = REDRAW_MOTION;
1507 case OP_DECRYPT_COPY:
1508 case OP_DECRYPT_SAVE:
1512 case OP_COPY_MESSAGE:
1514 case OP_DECODE_COPY:
1515 case OP_DECODE_SAVE:
1518 if (mutt_save_message (tag ? NULL : CURHDR,
1519 (op == OP_DECRYPT_SAVE) ||
1520 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1521 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1522 (op == OP_DECRYPT_SAVE)
1523 || (op == OP_DECRYPT_COPY)
1524 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1531 menu->redraw |= REDRAW_INDEX;
1532 else if (option (OPTRESOLVE)) {
1533 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1534 menu->current = menu->oldcurrent;
1535 menu->redraw |= REDRAW_CURRENT;
1538 menu->redraw |= REDRAW_MOTION_RESYNCH;
1541 menu->redraw |= REDRAW_CURRENT;
1545 case OP_MAIN_NEXT_NEW:
1546 case OP_MAIN_NEXT_UNREAD:
1547 case OP_MAIN_PREV_NEW:
1548 case OP_MAIN_PREV_UNREAD:
1549 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1550 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1553 int first_unread = -1;
1561 for (j = 0; j != Context->vcount; j++) {
1562 #define CURHDRi Context->hdrs[Context->v2r[i]]
1563 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1564 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1566 if (i > Context->vcount - 1) {
1567 mutt_message _("Search wrapped to top.");
1575 mutt_message _("Search wrapped to bottom.");
1577 i = Context->vcount - 1;
1581 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1582 if (UNREAD (CURHDRi) && first_unread == -1)
1584 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1587 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1588 if (first_unread == -1)
1590 if ((!CURHDRi->old) && first_new == -1)
1594 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_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)
1604 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1605 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1606 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1608 menu->current = first_new;
1609 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1610 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1611 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1612 && first_unread != -1)
1613 menu->current = first_unread;
1615 if (menu->current == -1) {
1616 menu->current = menu->oldcurrent;
1617 mutt_error ("%s%s.",
1618 (op == OP_MAIN_NEXT_NEW
1620 OP_MAIN_PREV_NEW) ? _("No new messages") :
1621 _("No unread messages"),
1622 Context->pattern ? _(" in this limited view") : "");
1624 else if (menu->menu == MENU_PAGER) {
1625 op = OP_DISPLAY_MESSAGE;
1629 menu->redraw = REDRAW_MOTION;
1632 case OP_FLAG_MESSAGE:
1638 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1641 for (j = 0; j < Context->vcount; j++) {
1642 if (Context->hdrs[Context->v2r[j]]->tagged)
1643 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1644 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1647 menu->redraw |= REDRAW_INDEX;
1650 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1651 if (option (OPTRESOLVE)) {
1652 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1653 menu->current = menu->oldcurrent;
1654 menu->redraw = REDRAW_CURRENT;
1657 menu->redraw = REDRAW_MOTION_RESYNCH;
1660 menu->redraw = REDRAW_CURRENT;
1662 menu->redraw |= REDRAW_STATUS;
1671 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1674 for (j = 0; j < Context->vcount; j++) {
1675 if (Context->hdrs[Context->v2r[j]]->tagged) {
1676 if (Context->hdrs[Context->v2r[j]]->read ||
1677 Context->hdrs[Context->v2r[j]]->old)
1678 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1681 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1685 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1688 if (CURHDR->read || CURHDR->old)
1689 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1691 mutt_set_flag (Context, CURHDR, M_READ, 1);
1693 if (option (OPTRESOLVE)) {
1694 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1695 menu->current = menu->oldcurrent;
1696 menu->redraw = REDRAW_CURRENT;
1699 menu->redraw = REDRAW_MOTION_RESYNCH;
1702 menu->redraw = REDRAW_CURRENT;
1703 menu->redraw |= REDRAW_STATUS;
1707 case OP_TOGGLE_WRITE:
1710 if (mx_toggle_write (Context) == 0)
1711 menu->redraw |= REDRAW_STATUS;
1714 case OP_MAIN_NEXT_THREAD:
1715 case OP_MAIN_NEXT_SUBTHREAD:
1716 case OP_MAIN_PREV_THREAD:
1717 case OP_MAIN_PREV_SUBTHREAD:
1722 case OP_MAIN_NEXT_THREAD:
1723 menu->current = mutt_next_thread (CURHDR);
1726 case OP_MAIN_NEXT_SUBTHREAD:
1727 menu->current = mutt_next_subthread (CURHDR);
1730 case OP_MAIN_PREV_THREAD:
1731 menu->current = mutt_previous_thread (CURHDR);
1734 case OP_MAIN_PREV_SUBTHREAD:
1735 menu->current = mutt_previous_subthread (CURHDR);
1739 if (menu->current < 0) {
1740 menu->current = menu->oldcurrent;
1741 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1742 mutt_error (_("No more threads."));
1745 mutt_error (_("You are on the first thread."));
1747 else if (menu->menu == MENU_PAGER) {
1748 op = OP_DISPLAY_MESSAGE;
1752 menu->redraw = REDRAW_MOTION;
1755 case OP_MAIN_PARENT_MESSAGE:
1760 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1761 menu->current = menu->oldcurrent;
1763 else if (menu->menu == MENU_PAGER) {
1764 op = OP_DISPLAY_MESSAGE;
1768 menu->redraw = REDRAW_MOTION;
1771 case OP_MAIN_SET_FLAG:
1772 case OP_MAIN_CLEAR_FLAG:
1778 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1780 menu->redraw = REDRAW_STATUS;
1782 menu->redraw |= REDRAW_INDEX;
1783 else if (option (OPTRESOLVE)) {
1784 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1785 menu->current = menu->oldcurrent;
1786 menu->redraw |= REDRAW_CURRENT;
1789 menu->redraw |= REDRAW_MOTION_RESYNCH;
1792 menu->redraw |= REDRAW_CURRENT;
1796 case OP_MAIN_COLLAPSE_THREAD:
1800 if ((Sort & SORT_MASK) != SORT_THREADS) {
1801 mutt_error (_("Threading is not enabled."));
1806 if (CURHDR->collapsed) {
1807 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1808 mutt_set_virtual (Context);
1809 if (option (OPTUNCOLLAPSEJUMP))
1810 menu->current = mutt_thread_next_unread (Context, CURHDR);
1812 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1813 menu->current = mutt_collapse_thread (Context, CURHDR);
1814 mutt_set_virtual (Context);
1817 mutt_error (_("Thread contains unread messages."));
1822 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1826 case OP_MAIN_COLLAPSE_ALL:
1830 if ((Sort & SORT_MASK) != SORT_THREADS) {
1831 mutt_error (_("Threading is not enabled."));
1838 THREAD *thread, *top;
1841 if (CURHDR->collapsed)
1842 final = mutt_uncollapse_thread (Context, CURHDR);
1843 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1844 final = mutt_collapse_thread (Context, CURHDR);
1846 final = CURHDR->virtual;
1848 base = Context->hdrs[Context->v2r[final]];
1850 top = Context->tree;
1851 Context->collapsed = !Context->collapsed;
1852 while ((thread = top) != NULL) {
1853 while (!thread->message)
1854 thread = thread->child;
1855 h = thread->message;
1857 if (h->collapsed != Context->collapsed) {
1859 mutt_uncollapse_thread (Context, h);
1860 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1861 mutt_collapse_thread (Context, h);
1866 mutt_set_virtual (Context);
1867 for (j = 0; j < Context->vcount; j++) {
1868 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1874 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1878 /* --------------------------------------------------------------------
1879 * These functions are invoked directly from the internal-pager
1882 case OP_BOUNCE_MESSAGE:
1887 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1890 case OP_CREATE_ALIAS:
1892 mutt_create_alias (Context
1893 && Context->vcount ? CURHDR->env : NULL, NULL);
1894 MAYBE_REDRAW (menu->redraw);
1895 menu->redraw |= REDRAW_CURRENT;
1900 mutt_query_menu (NULL, 0);
1901 MAYBE_REDRAW (menu->redraw);
1904 case OP_PURGE_MESSAGE:
1911 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1914 mutt_tag_set_flag (M_DELETE, 1);
1915 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1916 if (option (OPTDELETEUNTAG))
1917 mutt_tag_set_flag (M_TAG, 0);
1918 menu->redraw = REDRAW_INDEX;
1921 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1922 mutt_set_flag (Context, CURHDR, M_PURGED,
1923 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1924 if (option (OPTDELETEUNTAG))
1925 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1926 if (option (OPTRESOLVE)) {
1927 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1928 menu->current = menu->oldcurrent;
1929 menu->redraw = REDRAW_CURRENT;
1931 else if (menu->menu == MENU_PAGER) {
1932 op = OP_DISPLAY_MESSAGE;
1936 menu->redraw |= REDRAW_MOTION_RESYNCH;
1939 menu->redraw = REDRAW_CURRENT;
1941 menu->redraw |= REDRAW_STATUS;
1944 case OP_DELETE_THREAD:
1945 case OP_DELETE_SUBTHREAD:
1951 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1953 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1954 op == OP_DELETE_THREAD ? 0 : 1);
1957 if (option (OPTDELETEUNTAG))
1958 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1959 op == OP_DELETE_THREAD ? 0 : 1);
1960 if (option (OPTRESOLVE))
1961 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1962 menu->current = menu->oldcurrent;
1963 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1969 if (Context && Context->magic == M_NNTP) {
1970 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1971 ((NNTP_DATA *) Context->data)->group))
1972 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1977 case OP_DISPLAY_ADDRESS:
1981 mutt_display_address (CURHDR->env);
1984 case OP_ENTER_COMMAND:
1986 CurrentMenu = MENU_MAIN;
1987 mutt_enter_command ();
1988 mutt_check_rescore (Context);
1989 if (option (OPTFORCEREDRAWINDEX))
1990 menu->redraw = REDRAW_FULL;
1991 unset_option (OPTFORCEREDRAWINDEX);
1992 unset_option (OPTFORCEREDRAWPAGER);
1995 case OP_EDIT_MESSAGE:
2002 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
2004 if (option (OPTPGPAUTODEC)
2005 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2006 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2007 mutt_edit_message (Context, tag ? NULL : CURHDR);
2008 menu->redraw = REDRAW_FULL;
2012 case OP_FORWARD_MESSAGE:
2017 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2018 menu->redraw = REDRAW_FULL;
2022 case OP_FORGET_PASSPHRASE:
2023 crypt_forget_passphrase ();
2026 case OP_GROUP_REPLY:
2031 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2032 tag ? NULL : CURHDR);
2033 menu->redraw = REDRAW_FULL;
2041 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2042 tag ? NULL : CURHDR);
2043 menu->redraw = REDRAW_FULL;
2049 ci_send_message (0, NULL, NULL, Context, NULL);
2050 menu->redraw = REDRAW_FULL;
2054 if (!(WithCrypto & APPLICATION_PGP))
2057 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2058 menu->redraw = REDRAW_FULL;
2062 case OP_EXTRACT_KEYS:
2067 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2068 menu->redraw = REDRAW_FULL;
2072 case OP_CHECK_TRADITIONAL:
2073 if (!(WithCrypto & APPLICATION_PGP))
2077 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2078 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2080 if (menu->menu == MENU_PAGER) {
2081 op = OP_DISPLAY_MESSAGE;
2090 mutt_pipe_message (tag ? NULL : CURHDR);
2091 MAYBE_REDRAW (menu->redraw);
2098 mutt_print_message (tag ? NULL : CURHDR);
2101 case OP_MAIN_READ_THREAD:
2102 case OP_MAIN_READ_SUBTHREAD:
2108 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2110 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2111 op == OP_MAIN_READ_THREAD ? 0 : 1);
2114 if (option (OPTRESOLVE)) {
2115 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2116 mutt_next_thread (CURHDR) :
2117 mutt_next_subthread (CURHDR))) == -1)
2118 menu->current = menu->oldcurrent;
2120 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2124 case OP_RECALL_MESSAGE:
2127 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2128 menu->redraw = REDRAW_FULL;
2138 for (j = 0; j < Context->vcount; j++) {
2139 if (Context->hdrs[Context->v2r[j]]->tagged)
2140 mutt_resend_message (NULL, Context,
2141 Context->hdrs[Context->v2r[j]]);
2145 mutt_resend_message (NULL, Context, CURHDR);
2147 menu->redraw = REDRAW_FULL;
2153 case OP_FORWARD_TO_GROUP:
2156 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2157 Context && Context->msgcount == 0) {
2158 mutt_error (_("There are no messages."));
2161 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2162 safe_strcasecmp (CURHDR->env->followup_to, "poster") ||
2163 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2164 _("Reply by mail as poster prefers?")) !=
2166 if (Context && Context->magic == M_NNTP
2167 && !((NNTP_DATA *) Context->data)->allowed
2168 && query_quadoption (OPT_TOMODERATED,
2170 ("Posting to this group not allowed, may be moderated. Continue?"))
2174 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2177 if (op == OP_FOLLOWUP)
2178 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2179 tag ? NULL : CURHDR);
2181 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2182 tag ? NULL : CURHDR);
2184 menu->redraw = REDRAW_FULL;
2194 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2195 menu->redraw = REDRAW_FULL;
2198 case OP_SHELL_ESCAPE:
2200 mutt_shell_escape ();
2201 MAYBE_REDRAW (menu->redraw);
2205 case OP_TAG_SUBTHREAD:
2209 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2210 op == OP_TAG_THREAD ? 0 : 1);
2213 if (option (OPTRESOLVE)) {
2214 menu->current = mutt_next_thread (CURHDR);
2216 if (menu->current == -1)
2217 menu->current = menu->oldcurrent;
2219 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2229 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2232 mutt_tag_set_flag (M_DELETE, 0);
2233 mutt_tag_set_flag (M_PURGED, 0);
2234 menu->redraw = REDRAW_INDEX;
2237 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2238 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2239 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2241 menu->redraw = REDRAW_MOTION_RESYNCH;
2244 menu->redraw = REDRAW_CURRENT;
2246 menu->redraw |= REDRAW_STATUS;
2249 case OP_UNDELETE_THREAD:
2250 case OP_UNDELETE_SUBTHREAD:
2256 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2258 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2259 op == OP_UNDELETE_THREAD ? 0 : 1)
2260 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2261 op == OP_UNDELETE_THREAD ? 0 : 1);
2264 if (option (OPTRESOLVE)) {
2265 if (op == OP_UNDELETE_THREAD)
2266 menu->current = mutt_next_thread (CURHDR);
2268 menu->current = mutt_next_subthread (CURHDR);
2270 if (menu->current == -1)
2271 menu->current = menu->oldcurrent;
2273 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2283 menu->redraw = REDRAW_FULL;
2286 case OP_VIEW_ATTACHMENTS:
2289 mutt_view_attachments (CURHDR);
2290 if (CURHDR->attach_del)
2291 Context->changed = 1;
2292 menu->redraw = REDRAW_FULL;
2302 case OP_SIDEBAR_SCROLL_UP:
2303 case OP_SIDEBAR_SCROLL_DOWN:
2304 case OP_SIDEBAR_NEXT:
2305 case OP_SIDEBAR_PREV:
2306 case OP_SIDEBAR_NEXT_NEW:
2307 case OP_SIDEBAR_PREV_NEW:
2308 sidebar_scroll (op, menu->menu);
2311 if (menu->menu == MENU_MAIN)
2312 km_error_key (MENU_MAIN);
2315 if (menu->menu == MENU_PAGER) {
2316 menu->menu = MENU_MAIN;
2317 menu->redraw = REDRAW_FULL;
2319 set_option (OPTWEED); /* turn header weeding back on. */
2328 /* Close all open IMAP connections */
2333 /* Close all open NNTP connections */
2338 mutt_menuDestroy (&menu);
2342 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2349 for (color = ColorIndexList; color; color = color->next)
2350 if (mutt_pattern_exec
2351 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2352 curhdr->pair = color->pair;
2355 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];