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 if (op != OP_SIDEBAR_OPEN)
1209 buffy_next (buf, sizeof (buf));
1212 if (op == OP_SIDEBAR_OPEN) {
1213 strncpy (buf, NONULL(sidebar_get_current ()), sizeof (buf));
1215 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1219 CLEARLINE (LINES - 1);
1224 if (option (OPTNEWS)) {
1225 unset_option (OPTNEWS);
1226 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1230 mutt_expand_path (buf, sizeof (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 ();
1275 sidebar_set_current (buf);
1278 /* buffy_check() must be done with mail-reader mode! */
1279 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1281 && (Context->magic ==
1282 M_NNTP)) ? IndexNewsHelp :
1285 mutt_clear_error ();
1286 buffy_check (1); /* force the buffy check after we have changed
1288 menu->redraw = REDRAW_FULL;
1289 set_option (OPTSEARCHINVALID);
1292 case OP_DISPLAY_MESSAGE:
1293 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1298 * toggle the weeding of headers so that a user can press the key
1299 * again while reading the message.
1301 if (op == OP_DISPLAY_HEADERS)
1302 toggle_option (OPTWEED);
1304 unset_option (OPTNEEDRESORT);
1306 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1307 mutt_uncollapse_thread (Context, CURHDR);
1308 mutt_set_virtual (Context);
1309 if (option (OPTUNCOLLAPSEJUMP))
1310 menu->current = mutt_thread_next_unread (Context, CURHDR);
1313 if ((op = mutt_display_message (CURHDR)) == -1) {
1314 unset_option (OPTNEEDRESORT);
1318 menu->menu = MENU_PAGER;
1319 menu->oldcurrent = menu->current;
1325 if (menu->menu == MENU_MAIN && attach_msg) {
1330 if ((menu->menu == MENU_MAIN)
1331 && (query_quadoption (OPT_QUIT,
1332 _("Exit Mutt-ng without saving?")) == M_YES))
1335 mx_fastclose_mailbox (Context);
1347 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1348 /* if we were in the pager, redisplay the message */
1349 if (menu->menu == MENU_PAGER) {
1350 op = OP_DISPLAY_MESSAGE;
1354 menu->redraw = REDRAW_CURRENT;
1357 case OP_MAIN_BREAK_THREAD:
1363 if ((Sort & SORT_MASK) != SORT_THREADS)
1364 mutt_error (_("Threading is not enabled."));
1368 HEADER *oldcur = CURHDR;
1370 mutt_break_thread (CURHDR);
1371 mutt_sort_headers (Context, 1);
1372 menu->current = oldcur->virtual;
1375 Context->changed = 1;
1376 mutt_message _("Thread broken");
1378 if (menu->menu == MENU_PAGER) {
1379 op = OP_DISPLAY_MESSAGE;
1383 menu->redraw |= REDRAW_INDEX;
1387 case OP_MAIN_LINK_THREADS:
1393 if ((Sort & SORT_MASK) != SORT_THREADS)
1394 mutt_error (_("Threading is not enabled."));
1396 else if (!CURHDR->env->message_id)
1397 mutt_error (_("No Message-ID: header available to link thread"));
1399 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1400 mutt_error (_("First, please tag a message to be linked here"));
1403 HEADER *oldcur = CURHDR;
1405 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1407 mutt_sort_headers (Context, 1);
1408 menu->current = oldcur->virtual;
1410 Context->changed = 1;
1411 mutt_message _("Threads linked");
1414 mutt_error (_("No thread linked"));
1417 if (menu->menu == MENU_PAGER) {
1418 op = OP_DISPLAY_MESSAGE;
1422 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1425 case OP_MAIN_NEXT_UNDELETED:
1429 if (menu->current >= Context->vcount - 1) {
1430 if (menu->menu == MENU_MAIN)
1431 mutt_error (_("You are on the last message."));
1435 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1436 menu->current = menu->oldcurrent;
1437 if (menu->menu == MENU_MAIN)
1438 mutt_error (_("No undeleted messages."));
1440 else if (menu->menu == MENU_PAGER) {
1441 op = OP_DISPLAY_MESSAGE;
1445 menu->redraw = REDRAW_MOTION;
1452 if (menu->current >= Context->vcount - 1) {
1453 if (menu->menu == MENU_MAIN)
1454 mutt_error (_("You are on the last message."));
1459 if (menu->menu == MENU_PAGER) {
1460 op = OP_DISPLAY_MESSAGE;
1464 menu->redraw = REDRAW_MOTION;
1467 case OP_MAIN_PREV_UNDELETED:
1471 if (menu->current < 1) {
1472 mutt_error (_("You are on the first message."));
1476 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1477 menu->current = menu->oldcurrent;
1478 if (menu->menu == MENU_MAIN)
1479 mutt_error (_("No undeleted messages."));
1481 else if (menu->menu == MENU_PAGER) {
1482 op = OP_DISPLAY_MESSAGE;
1486 menu->redraw = REDRAW_MOTION;
1493 if (menu->current < 1) {
1494 if (menu->menu == MENU_MAIN)
1495 mutt_error (_("You are on the first message."));
1500 if (menu->menu == MENU_PAGER) {
1501 op = OP_DISPLAY_MESSAGE;
1505 menu->redraw = REDRAW_MOTION;
1508 case OP_DECRYPT_COPY:
1509 case OP_DECRYPT_SAVE:
1513 case OP_COPY_MESSAGE:
1515 case OP_DECODE_COPY:
1516 case OP_DECODE_SAVE:
1519 if (mutt_save_message (tag ? NULL : CURHDR,
1520 (op == OP_DECRYPT_SAVE) ||
1521 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1522 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1523 (op == OP_DECRYPT_SAVE)
1524 || (op == OP_DECRYPT_COPY)
1525 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1532 menu->redraw |= REDRAW_INDEX;
1533 else if (option (OPTRESOLVE)) {
1534 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1535 menu->current = menu->oldcurrent;
1536 menu->redraw |= REDRAW_CURRENT;
1539 menu->redraw |= REDRAW_MOTION_RESYNCH;
1542 menu->redraw |= REDRAW_CURRENT;
1546 case OP_MAIN_NEXT_NEW:
1547 case OP_MAIN_NEXT_UNREAD:
1548 case OP_MAIN_PREV_NEW:
1549 case OP_MAIN_PREV_UNREAD:
1550 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1551 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1554 int first_unread = -1;
1562 for (j = 0; j != Context->vcount; j++) {
1563 #define CURHDRi Context->hdrs[Context->v2r[i]]
1564 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1565 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1567 if (i > Context->vcount - 1) {
1568 mutt_message _("Search wrapped to top.");
1576 mutt_message _("Search wrapped to bottom.");
1578 i = Context->vcount - 1;
1582 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1583 if (UNREAD (CURHDRi) && first_unread == -1)
1585 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1588 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1589 if (first_unread == -1)
1591 if ((!CURHDRi->old) && first_new == -1)
1595 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1598 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1599 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1600 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1605 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1606 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1607 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1609 menu->current = first_new;
1610 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1611 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1612 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1613 && first_unread != -1)
1614 menu->current = first_unread;
1616 if (menu->current == -1) {
1617 menu->current = menu->oldcurrent;
1618 mutt_error ("%s%s.",
1619 (op == OP_MAIN_NEXT_NEW
1621 OP_MAIN_PREV_NEW) ? _("No new messages") :
1622 _("No unread messages"),
1623 Context->pattern ? _(" in this limited view") : "");
1625 else if (menu->menu == MENU_PAGER) {
1626 op = OP_DISPLAY_MESSAGE;
1630 menu->redraw = REDRAW_MOTION;
1633 case OP_FLAG_MESSAGE:
1639 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1642 for (j = 0; j < Context->vcount; j++) {
1643 if (Context->hdrs[Context->v2r[j]]->tagged)
1644 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1645 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1648 menu->redraw |= REDRAW_INDEX;
1651 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1652 if (option (OPTRESOLVE)) {
1653 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1654 menu->current = menu->oldcurrent;
1655 menu->redraw = REDRAW_CURRENT;
1658 menu->redraw = REDRAW_MOTION_RESYNCH;
1661 menu->redraw = REDRAW_CURRENT;
1663 menu->redraw |= REDRAW_STATUS;
1672 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1675 for (j = 0; j < Context->vcount; j++) {
1676 if (Context->hdrs[Context->v2r[j]]->tagged) {
1677 if (Context->hdrs[Context->v2r[j]]->read ||
1678 Context->hdrs[Context->v2r[j]]->old)
1679 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1682 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1686 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1689 if (CURHDR->read || CURHDR->old)
1690 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1692 mutt_set_flag (Context, CURHDR, M_READ, 1);
1694 if (option (OPTRESOLVE)) {
1695 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1696 menu->current = menu->oldcurrent;
1697 menu->redraw = REDRAW_CURRENT;
1700 menu->redraw = REDRAW_MOTION_RESYNCH;
1703 menu->redraw = REDRAW_CURRENT;
1704 menu->redraw |= REDRAW_STATUS;
1708 case OP_TOGGLE_WRITE:
1711 if (mx_toggle_write (Context) == 0)
1712 menu->redraw |= REDRAW_STATUS;
1715 case OP_MAIN_NEXT_THREAD:
1716 case OP_MAIN_NEXT_SUBTHREAD:
1717 case OP_MAIN_PREV_THREAD:
1718 case OP_MAIN_PREV_SUBTHREAD:
1723 case OP_MAIN_NEXT_THREAD:
1724 menu->current = mutt_next_thread (CURHDR);
1727 case OP_MAIN_NEXT_SUBTHREAD:
1728 menu->current = mutt_next_subthread (CURHDR);
1731 case OP_MAIN_PREV_THREAD:
1732 menu->current = mutt_previous_thread (CURHDR);
1735 case OP_MAIN_PREV_SUBTHREAD:
1736 menu->current = mutt_previous_subthread (CURHDR);
1740 if (menu->current < 0) {
1741 menu->current = menu->oldcurrent;
1742 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1743 mutt_error (_("No more threads."));
1746 mutt_error (_("You are on the first thread."));
1748 else if (menu->menu == MENU_PAGER) {
1749 op = OP_DISPLAY_MESSAGE;
1753 menu->redraw = REDRAW_MOTION;
1756 case OP_MAIN_PARENT_MESSAGE:
1761 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1762 menu->current = menu->oldcurrent;
1764 else if (menu->menu == MENU_PAGER) {
1765 op = OP_DISPLAY_MESSAGE;
1769 menu->redraw = REDRAW_MOTION;
1772 case OP_MAIN_SET_FLAG:
1773 case OP_MAIN_CLEAR_FLAG:
1779 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1781 menu->redraw = REDRAW_STATUS;
1783 menu->redraw |= REDRAW_INDEX;
1784 else if (option (OPTRESOLVE)) {
1785 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1786 menu->current = menu->oldcurrent;
1787 menu->redraw |= REDRAW_CURRENT;
1790 menu->redraw |= REDRAW_MOTION_RESYNCH;
1793 menu->redraw |= REDRAW_CURRENT;
1797 case OP_MAIN_COLLAPSE_THREAD:
1801 if ((Sort & SORT_MASK) != SORT_THREADS) {
1802 mutt_error (_("Threading is not enabled."));
1807 if (CURHDR->collapsed) {
1808 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1809 mutt_set_virtual (Context);
1810 if (option (OPTUNCOLLAPSEJUMP))
1811 menu->current = mutt_thread_next_unread (Context, CURHDR);
1813 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1814 menu->current = mutt_collapse_thread (Context, CURHDR);
1815 mutt_set_virtual (Context);
1818 mutt_error (_("Thread contains unread messages."));
1823 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1827 case OP_MAIN_COLLAPSE_ALL:
1831 if ((Sort & SORT_MASK) != SORT_THREADS) {
1832 mutt_error (_("Threading is not enabled."));
1839 THREAD *thread, *top;
1842 if (CURHDR->collapsed)
1843 final = mutt_uncollapse_thread (Context, CURHDR);
1844 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1845 final = mutt_collapse_thread (Context, CURHDR);
1847 final = CURHDR->virtual;
1849 base = Context->hdrs[Context->v2r[final]];
1851 top = Context->tree;
1852 Context->collapsed = !Context->collapsed;
1853 while ((thread = top) != NULL) {
1854 while (!thread->message)
1855 thread = thread->child;
1856 h = thread->message;
1858 if (h->collapsed != Context->collapsed) {
1860 mutt_uncollapse_thread (Context, h);
1861 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1862 mutt_collapse_thread (Context, h);
1867 mutt_set_virtual (Context);
1868 for (j = 0; j < Context->vcount; j++) {
1869 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1875 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1879 /* --------------------------------------------------------------------
1880 * These functions are invoked directly from the internal-pager
1883 case OP_BOUNCE_MESSAGE:
1888 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1891 case OP_CREATE_ALIAS:
1893 mutt_create_alias (Context
1894 && Context->vcount ? CURHDR->env : NULL, NULL);
1895 MAYBE_REDRAW (menu->redraw);
1896 menu->redraw |= REDRAW_CURRENT;
1901 mutt_query_menu (NULL, 0);
1902 MAYBE_REDRAW (menu->redraw);
1905 case OP_PURGE_MESSAGE:
1912 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1915 mutt_tag_set_flag (M_DELETE, 1);
1916 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1917 if (option (OPTDELETEUNTAG))
1918 mutt_tag_set_flag (M_TAG, 0);
1919 menu->redraw = REDRAW_INDEX;
1922 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1923 mutt_set_flag (Context, CURHDR, M_PURGED,
1924 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1925 if (option (OPTDELETEUNTAG))
1926 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1927 if (option (OPTRESOLVE)) {
1928 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1929 menu->current = menu->oldcurrent;
1930 menu->redraw = REDRAW_CURRENT;
1932 else if (menu->menu == MENU_PAGER) {
1933 op = OP_DISPLAY_MESSAGE;
1937 menu->redraw |= REDRAW_MOTION_RESYNCH;
1940 menu->redraw = REDRAW_CURRENT;
1942 menu->redraw |= REDRAW_STATUS;
1945 case OP_DELETE_THREAD:
1946 case OP_DELETE_SUBTHREAD:
1952 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1954 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1955 op == OP_DELETE_THREAD ? 0 : 1);
1958 if (option (OPTDELETEUNTAG))
1959 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1960 op == OP_DELETE_THREAD ? 0 : 1);
1961 if (option (OPTRESOLVE))
1962 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1963 menu->current = menu->oldcurrent;
1964 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1970 if (Context && Context->magic == M_NNTP) {
1971 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1972 ((NNTP_DATA *) Context->data)->group))
1973 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1978 case OP_DISPLAY_ADDRESS:
1982 mutt_display_address (CURHDR->env);
1985 case OP_ENTER_COMMAND:
1987 CurrentMenu = MENU_MAIN;
1988 mutt_enter_command ();
1989 mutt_check_rescore (Context);
1990 if (option (OPTFORCEREDRAWINDEX))
1991 menu->redraw = REDRAW_FULL;
1992 unset_option (OPTFORCEREDRAWINDEX);
1993 unset_option (OPTFORCEREDRAWPAGER);
1996 case OP_EDIT_MESSAGE:
2003 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
2005 if (option (OPTPGPAUTODEC)
2006 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2007 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2008 mutt_edit_message (Context, tag ? NULL : CURHDR);
2009 menu->redraw = REDRAW_FULL;
2013 case OP_FORWARD_MESSAGE:
2018 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2019 menu->redraw = REDRAW_FULL;
2023 case OP_FORGET_PASSPHRASE:
2024 crypt_forget_passphrase ();
2027 case OP_GROUP_REPLY:
2032 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2033 tag ? NULL : CURHDR);
2034 menu->redraw = REDRAW_FULL;
2042 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2043 tag ? NULL : CURHDR);
2044 menu->redraw = REDRAW_FULL;
2050 ci_send_message (0, NULL, NULL, Context, NULL);
2051 menu->redraw = REDRAW_FULL;
2055 if (!(WithCrypto & APPLICATION_PGP))
2058 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2059 menu->redraw = REDRAW_FULL;
2063 case OP_EXTRACT_KEYS:
2068 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2069 menu->redraw = REDRAW_FULL;
2073 case OP_CHECK_TRADITIONAL:
2074 if (!(WithCrypto & APPLICATION_PGP))
2078 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2079 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2081 if (menu->menu == MENU_PAGER) {
2082 op = OP_DISPLAY_MESSAGE;
2091 mutt_pipe_message (tag ? NULL : CURHDR);
2092 MAYBE_REDRAW (menu->redraw);
2099 mutt_print_message (tag ? NULL : CURHDR);
2102 case OP_MAIN_READ_THREAD:
2103 case OP_MAIN_READ_SUBTHREAD:
2109 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2111 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2112 op == OP_MAIN_READ_THREAD ? 0 : 1);
2115 if (option (OPTRESOLVE)) {
2116 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2117 mutt_next_thread (CURHDR) :
2118 mutt_next_subthread (CURHDR))) == -1)
2119 menu->current = menu->oldcurrent;
2121 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2125 case OP_RECALL_MESSAGE:
2128 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2129 menu->redraw = REDRAW_FULL;
2139 for (j = 0; j < Context->vcount; j++) {
2140 if (Context->hdrs[Context->v2r[j]]->tagged)
2141 mutt_resend_message (NULL, Context,
2142 Context->hdrs[Context->v2r[j]]);
2146 mutt_resend_message (NULL, Context, CURHDR);
2148 menu->redraw = REDRAW_FULL;
2154 case OP_FORWARD_TO_GROUP:
2157 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2158 Context && Context->msgcount == 0) {
2159 mutt_error (_("There are no messages."));
2162 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2163 safe_strcasecmp (CURHDR->env->followup_to, "poster") ||
2164 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2165 _("Reply by mail as poster prefers?")) !=
2167 if (Context && Context->magic == M_NNTP
2168 && !((NNTP_DATA *) Context->data)->allowed
2169 && query_quadoption (OPT_TOMODERATED,
2171 ("Posting to this group not allowed, may be moderated. Continue?"))
2175 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2178 if (op == OP_FOLLOWUP)
2179 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2180 tag ? NULL : CURHDR);
2182 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2183 tag ? NULL : CURHDR);
2185 menu->redraw = REDRAW_FULL;
2195 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2196 menu->redraw = REDRAW_FULL;
2199 case OP_SHELL_ESCAPE:
2201 mutt_shell_escape ();
2202 MAYBE_REDRAW (menu->redraw);
2206 case OP_TAG_SUBTHREAD:
2210 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2211 op == OP_TAG_THREAD ? 0 : 1);
2214 if (option (OPTRESOLVE)) {
2215 menu->current = mutt_next_thread (CURHDR);
2217 if (menu->current == -1)
2218 menu->current = menu->oldcurrent;
2220 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2230 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2233 mutt_tag_set_flag (M_DELETE, 0);
2234 mutt_tag_set_flag (M_PURGED, 0);
2235 menu->redraw = REDRAW_INDEX;
2238 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2239 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2240 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2242 menu->redraw = REDRAW_MOTION_RESYNCH;
2245 menu->redraw = REDRAW_CURRENT;
2247 menu->redraw |= REDRAW_STATUS;
2250 case OP_UNDELETE_THREAD:
2251 case OP_UNDELETE_SUBTHREAD:
2257 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2259 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2260 op == OP_UNDELETE_THREAD ? 0 : 1)
2261 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2262 op == OP_UNDELETE_THREAD ? 0 : 1);
2265 if (option (OPTRESOLVE)) {
2266 if (op == OP_UNDELETE_THREAD)
2267 menu->current = mutt_next_thread (CURHDR);
2269 menu->current = mutt_next_subthread (CURHDR);
2271 if (menu->current == -1)
2272 menu->current = menu->oldcurrent;
2274 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2284 menu->redraw = REDRAW_FULL;
2287 case OP_VIEW_ATTACHMENTS:
2290 mutt_view_attachments (CURHDR);
2291 if (CURHDR->attach_del)
2292 Context->changed = 1;
2293 menu->redraw = REDRAW_FULL;
2303 case OP_SIDEBAR_SCROLL_UP:
2304 case OP_SIDEBAR_SCROLL_DOWN:
2305 case OP_SIDEBAR_NEXT:
2306 case OP_SIDEBAR_PREV:
2307 case OP_SIDEBAR_NEXT_NEW:
2308 case OP_SIDEBAR_PREV_NEW:
2309 sidebar_scroll (op, menu->menu);
2312 if (menu->menu == MENU_MAIN)
2313 km_error_key (MENU_MAIN);
2316 if (menu->menu == MENU_PAGER) {
2317 menu->menu = MENU_MAIN;
2318 menu->redraw = REDRAW_FULL;
2320 set_option (OPTWEED); /* turn header weeding back on. */
2329 /* Close all open IMAP connections */
2334 /* Close all open NNTP connections */
2339 mutt_menuDestroy (&menu);
2343 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2350 for (color = ColorIndexList; color; color = color->next)
2351 if (mutt_pattern_exec
2352 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2353 curhdr->pair = color->pair;
2356 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];