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"
33 #include "imap_private.h"
36 #include "mutt_crypt.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)); \
90 /* the error message returned here could be better. */
91 #define CHECK_IMAP_ACL(aclbit) if (Context->magic == M_IMAP) \
92 if (mutt_bit_isset (((IMAP_DATA *)Context->data)->capabilities, ACL) \
93 && !mutt_bit_isset(((IMAP_DATA *)Context->data)->rights,aclbit)){ \
95 mutt_error ("Operation not permitted by the IMAP ACL for this mailbox"); \
100 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
103 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
107 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
108 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
109 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
111 extern const char *ReleaseDate;
112 extern size_t UngetCount;
114 static void set_xterm_title_bar (char *title)
116 fputs ("\033]2;", stdout);
117 fputs (title, stdout);
118 fputs ("\007", stdout);
122 static void set_xterm_icon_name (char *name)
124 fputs ("\033]1;", stdout);
125 fputs (name, stdout);
126 fputs ("\007", stdout);
130 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
133 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
134 int edgemsgno, reverse = Sort & SORT_REVERSE;
135 HEADER *h = Context->hdrs[Context->v2r[num]];
138 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
139 flag |= M_FORMAT_TREE; /* display the thread tree */
140 if (h->display_subject)
141 flag |= M_FORMAT_FORCESUBJ;
144 if (menu->top + menu->pagelen > menu->max)
145 edgemsgno = Context->v2r[menu->max - 1];
147 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
150 edgemsgno = Context->v2r[menu->top];
152 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
156 /* if no ancestor is visible on current screen, provisionally force
158 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
160 flag |= M_FORMAT_FORCESUBJ;
163 else if (tmp->message->virtual >= 0)
166 if (flag & M_FORMAT_FORCESUBJ) {
167 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
171 /* ...but if a previous sibling is available, don't force it */
172 if (reverse ? tmp->message->msgno >
173 edgemsgno : tmp->message->msgno < edgemsgno)
175 else if (tmp->message->virtual >= 0) {
176 flag &= ~M_FORMAT_FORCESUBJ;
184 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
187 int index_color (int index_no)
189 HEADER *h = Context->hdrs[Context->v2r[index_no]];
194 mutt_set_header_color (Context, h);
198 static int ci_next_undeleted (int msgno)
202 for (i = msgno + 1; i < Context->vcount; i++)
203 if (!Context->hdrs[Context->v2r[i]]->deleted)
208 static int ci_previous_undeleted (int msgno)
212 for (i = msgno - 1; i >= 0; i--)
213 if (!Context->hdrs[Context->v2r[i]]->deleted)
218 /* Return the index of the first new message, or failing that, the first
221 static int ci_first_message (void)
225 if (Context && Context->msgcount) {
226 for (i = 0; i < Context->vcount; i++) {
227 if (!Context->hdrs[Context->v2r[i]]->read &&
228 !Context->hdrs[Context->v2r[i]]->deleted) {
229 if (!Context->hdrs[Context->v2r[i]]->old)
238 /* If Sort is reverse and not threaded, the latest message is first.
239 * If Sort is threaded, the latest message is first iff exactly one
240 * of Sort and SortAux are reverse.
242 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
243 ((Sort & SORT_MASK) == SORT_THREADS &&
244 ((Sort ^ SortAux) & SORT_REVERSE)))
247 return (Context->vcount ? Context->vcount - 1 : 0);
252 /* This should be in mx.c, but it only gets used here. */
253 static int mx_toggle_write (CONTEXT * ctx)
259 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
264 if (ctx->dontwrite) {
266 mutt_message (_("Changes to folder will be written on folder exit."));
270 mutt_message (_("Changes to folder will not be written."));
276 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
277 int oldcount, int index_hint)
279 /* store pointers to the newly added messages */
280 HEADER **save_new = NULL;
283 /* take note of the current message */
285 if (menu->current < Context->vcount)
286 menu->oldcurrent = index_hint;
288 oldcount = 0; /* invalid message number! */
291 /* We are in a limited view. Check if the new message(s) satisfy
292 * the limit criteria. If they do, set their virtual msgno so that
293 * they will be visible in the limited view */
294 if (Context->pattern) {
295 #define THIS_BODY Context->hdrs[j]->content
296 if (oldcount || check == M_REOPENED) {
297 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount;
299 if (mutt_pattern_exec
300 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
302 Context->hdrs[j]->virtual = Context->vcount;
303 Context->v2r[Context->vcount] = j;
304 Context->hdrs[j]->limited = 1;
307 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
314 /* save the list of new messages */
315 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
317 (HEADER **) safe_malloc (sizeof (HEADER *) *
318 (Context->msgcount - oldcount));
319 for (j = oldcount; j < Context->msgcount; j++)
320 save_new[j - oldcount] = Context->hdrs[j];
323 /* if the mailbox was reopened, need to rethread from scratch */
324 mutt_sort_headers (Context, (check == M_REOPENED));
326 /* uncollapse threads with new mail */
327 if ((Sort & SORT_MASK) == SORT_THREADS) {
328 if (check == M_REOPENED) {
331 Context->collapsed = 0;
333 for (h = Context->tree; h; h = h->next) {
334 for (j = h; !j->message; j = j->child);
335 mutt_uncollapse_thread (Context, j->message);
337 mutt_set_virtual (Context);
340 for (j = 0; j < Context->msgcount - oldcount; j++) {
343 for (k = 0; k < Context->msgcount; k++) {
344 HEADER *h = Context->hdrs[k];
346 if (h == save_new[j] && (!Context->pattern || h->limited))
347 mutt_uncollapse_thread (Context, h);
351 mutt_set_virtual (Context);
357 /* restore the current message to the message it was pointing to */
358 for (j = 0; j < Context->vcount; j++) {
359 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
366 if (menu->current < 0)
367 menu->current = ci_first_message ();
371 static void resort_index (MUTTMENU * menu)
374 HEADER *current = CURHDR;
377 mutt_sort_headers (Context, 0);
378 /* Restore the current message */
380 for (i = 0; i < Context->vcount; i++) {
381 if (Context->hdrs[Context->v2r[i]] == current) {
387 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
388 menu->current = mutt_parent_message (Context, current);
390 if (menu->current < 0)
391 menu->current = ci_first_message ();
393 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
396 struct mapping_t IndexHelp[] = {
397 {N_("Quit"), OP_QUIT},
398 {N_("Del"), OP_DELETE},
399 {N_("Undel"), OP_UNDELETE},
400 {N_("Save"), OP_SAVE},
401 {N_("Mail"), OP_MAIL},
402 {N_("Reply"), OP_REPLY},
403 {N_("Group"), OP_GROUP_REPLY},
404 {N_("Help"), OP_HELP},
409 struct mapping_t IndexNewsHelp[] = {
410 {N_("Quit"), OP_QUIT},
411 {N_("Del"), OP_DELETE},
412 {N_("Undel"), OP_UNDELETE},
413 {N_("Save"), OP_SAVE},
414 {N_("Post"), OP_POST},
415 {N_("Followup"), OP_FOLLOWUP},
416 {N_("Catchup"), OP_CATCHUP},
417 {N_("Help"), OP_HELP},
422 /* This function handles the message index window as well as commands returned
423 * from the pager (MENU_PAGER).
425 int mutt_index_menu (void)
427 char buf[LONG_STRING], helpstr[SHORT_STRING];
430 int done = 0; /* controls when to exit the "event" loop */
432 int tag = 0; /* has the tag-prefix command been pressed? */
437 char *cp; /* temporary variable. */
438 int index_hint; /* used to restore cursor position */
439 int do_buffy_notify = 1;
440 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
441 int attach_msg = option (OPTATTACHMSG);
443 menu = mutt_new_menu ();
444 menu->menu = MENU_MAIN;
446 menu->pagelen = LINES - 3;
447 menu->make_entry = index_make_entry;
448 menu->color = index_color;
449 menu->current = ci_first_message ();
450 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
453 && (Context->magic ==
454 M_NNTP)) ? IndexNewsHelp :
459 mutt_buffy_check (1); /* force the buffy check after we enter the folder */
460 /* record folder we open to place sidebar indicator properly */
461 if (Context && Context->path)
462 sidebar_set_current (Context->path);
466 tag = 0; /* clear the tag-prefix */
468 menu->max = Context ? Context->vcount : 0;
469 oldcount = Context ? Context->msgcount : 0;
471 /* check if we need to resort the index because just about
472 * any 'op' below could do mutt_enter_command(), either here or
473 * from any new menu launched, and change $sort/$sort_aux
475 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
478 if (option (OPTREDRAWTREE) && Context && Context->msgcount
479 && (Sort & SORT_MASK) == SORT_THREADS) {
480 mutt_draw_tree (Context);
481 menu->redraw |= REDRAW_STATUS;
482 unset_option (OPTREDRAWTREE);
485 if (Context && !attach_msg) {
488 /* check for new mail in the mailbox. If nonzero, then something has
489 * changed about the file (either we got new mail or the file was
490 * modified underneath us.)
494 imap_allow_reopen (Context);
497 index_hint = (Context->vcount && menu->current >= 0
498 && menu->current < Context->vcount) ? CURHDR->index : 0;
500 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
501 if (!Context->path) {
502 /* fatal error occurred */
504 menu->redraw = REDRAW_FULL;
506 set_option (OPTSEARCHINVALID);
508 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
509 update_index (menu, Context, check, oldcount, index_hint);
511 /* notify the user of new mail */
512 if (check == M_REOPENED)
514 ("Mailbox was externally modified. Flags may be wrong."));
515 else if (check == M_NEW_MAIL) {
516 /* on new mail: redraw sidebar */
517 sidebar_draw (CurrentMenu);
518 mutt_message (_("New mail in this mailbox."));
520 if (option (OPTBEEPNEW))
523 else if (check == M_FLAGS)
524 mutt_message (_("Mailbox was externally modified."));
526 /* avoid the message being overwritten by buffy */
529 menu->redraw = REDRAW_FULL;
530 menu->max = Context->vcount;
532 set_option (OPTSEARCHINVALID);
538 imap_disallow_reopen (Context);
542 /* check for new mail in the incoming folders */
544 if ((newcount = mutt_buffy_check (0)) != oldcount) {
545 menu->redraw |= REDRAW_STATUS;
546 menu->redraw |= REDRAW_SIDEBAR;
548 if (do_buffy_notify) {
549 if (mutt_buffy_notify () && option (OPTBEEPNEW))
558 if (menu->redraw & REDRAW_SIDEBAR)
559 sidebar_draw (menu->menu);
560 if (menu->redraw & REDRAW_FULL) {
561 menu_redraw_full (menu);
562 sidebar_draw (menu->menu);
566 if (menu->menu == MENU_MAIN) {
567 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
568 menu_check_recenter (menu);
570 if (menu->redraw & REDRAW_INDEX) {
571 menu_redraw_index (menu);
572 menu->redraw |= REDRAW_STATUS;
574 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
575 menu_redraw_motion (menu);
576 else if (menu->redraw & REDRAW_CURRENT)
577 menu_redraw_current (menu);
580 if (menu->redraw & REDRAW_STATUS) {
582 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
584 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
585 SETCOLOR (MT_COLOR_STATUS);
586 mutt_paddstr (COLS, buf);
587 SETCOLOR (MT_COLOR_NORMAL);
588 sidebar_set_buffystats (Context);
589 menu->redraw &= ~REDRAW_STATUS;
590 if (option (OPTXTERMSETTITLES)) {
591 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
592 set_xterm_title_bar (buf);
593 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
594 set_xterm_icon_name (buf);
599 if (menu->current < menu->max)
600 menu->oldcurrent = menu->current;
602 menu->oldcurrent = -1;
604 if (option (OPTARROWCURSOR))
605 move (menu->current - menu->top + menu->offset, 2);
607 move (menu->current - menu->top + menu->offset, COLS - 1);
610 op = km_dokey (MENU_MAIN);
613 (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op));
615 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
618 mutt_resize_screen ();
619 menu->redraw = REDRAW_FULL;
620 menu->menu = MENU_MAIN;
622 menu->top = 0; /* so we scroll the right amount */
624 * force a real complete redraw. clrtobot() doesn't seem to be able
625 * to handle every case without this.
627 clearok (stdscr, TRUE);
633 continue; /* either user abort or timeout */
637 /* special handling for the tag-prefix function */
638 if (op == OP_TAG_PREFIX) {
640 mutt_error (_("No mailbox is open."));
645 if (!Context->tagged) {
646 mutt_error (_("No tagged messages."));
652 /* give visual indication that the next command is a tag- command */
653 mvaddstr (LINES - 1, 0, "tag-");
656 /* get the real command */
657 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
658 /* abort tag sequence */
659 CLEARLINE (LINES - 1);
663 else if (option (OPTAUTOTAG) && Context && Context->tagged)
666 if (op == OP_TAG_PREFIX_COND) {
668 mutt_error (_("No mailbox is open."));
673 if (!Context->tagged) {
676 while (UngetCount > 0) {
678 if (tmp.op == OP_END_COND)
681 mutt_message (_("Nothing to do."));
687 /* give visual indication that the next command is a tag- command */
688 mvaddstr (LINES - 1, 0, "tag-");
691 /* get the real command */
692 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
693 /* abort tag sequence */
694 CLEARLINE (LINES - 1);
702 if (menu->current < menu->max)
703 menu->oldcurrent = menu->current;
705 menu->oldcurrent = -1;
707 mutt_curs_set (1); /* fallback from the pager */
711 unset_option (OPTNEWS); /* for any case */
716 /* ----------------------------------------------------------------------
721 menu_bottom_page (menu);
724 menu_first_entry (menu);
727 menu_middle_page (menu);
733 menu_half_down (menu);
736 menu_next_line (menu);
739 menu_prev_line (menu);
742 menu_next_page (menu);
745 menu_prev_page (menu);
748 menu_last_entry (menu);
751 menu_top_page (menu);
754 menu_current_top (menu);
756 case OP_CURRENT_MIDDLE:
757 menu_current_middle (menu);
759 case OP_CURRENT_BOTTOM:
760 menu_current_bottom (menu);
767 if (Context->magic == M_NNTP) {
770 if (op == OP_GET_MESSAGE) {
772 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0)
777 LIST *ref = CURHDR->env->references;
780 mutt_error (_("Article has no parent reference!"));
784 strfcpy (buf, ref->data, sizeof (buf));
786 if (!Context->id_hash)
787 Context->id_hash = mutt_make_id_hash (Context);
788 if ((h = hash_find (Context->id_hash, buf))) {
789 if (h->virtual != -1) {
790 menu->current = h->virtual;
791 menu->redraw = REDRAW_MOTION_RESYNCH;
793 else if (h->collapsed) {
794 mutt_uncollapse_thread (Context, h);
795 mutt_set_virtual (Context);
796 menu->current = h->virtual;
797 menu->redraw = REDRAW_MOTION_RESYNCH;
800 mutt_error (_("Message not visible in limited view."));
803 if (nntp_check_msgid (Context, buf) == 0) {
804 h = Context->hdrs[Context->msgcount - 1];
805 mutt_sort_headers (Context, 0);
806 menu->current = h->virtual;
807 menu->redraw = REDRAW_FULL;
810 mutt_error (_("Article %s not found on server"), buf);
815 case OP_GET_CHILDREN:
816 case OP_RECONSTRUCT_THREAD:
818 if (Context->magic == M_NNTP) {
820 int old = CURHDR->index, i;
822 if (!CURHDR->env->message_id) {
823 mutt_error (_("No Message-Id. Unable to perform operation"));
828 if (!Context->id_hash)
829 Context->id_hash = mutt_make_id_hash (Context);
830 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
832 if (op == OP_RECONSTRUCT_THREAD) {
833 LIST *ref = CURHDR->env->references;
836 nntp_check_msgid (Context, ref->data);
837 /* the last msgid in References is the root message */
839 strfcpy (buf, ref->data, sizeof (buf));
843 mutt_message (_("Check for children of message..."));
845 if (nntp_check_children (Context, buf) == 0) {
846 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
847 h = hash_find (Context->id_hash, buf);
848 /* if the root message was retrieved, move to it */
850 menu->current = h->virtual;
851 else /* try to restore old position */
852 for (i = 0; i < Context->msgcount; i++)
853 if (Context->hdrs[i]->index == old) {
854 menu->current = Context->hdrs[i]->virtual;
855 /* As an added courtesy, recenter the menu
856 * with the current entry at the middle of the screen */
857 menu_check_recenter (menu);
858 menu_current_middle (menu);
861 menu->redraw = REDRAW_FULL;
871 if (isdigit (LastKey))
872 mutt_ungetch (LastKey, 0);
874 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
878 if (!isdigit ((unsigned char) buf[0])) {
879 mutt_error (_("Argument must be a message number."));
885 if (i > 0 && i <= Context->msgcount) {
886 for (j = i - 1; j < Context->msgcount; j++) {
887 if (Context->hdrs[j]->virtual != -1)
890 if (j >= Context->msgcount) {
891 for (j = i - 2; j >= 0; j--) {
892 if (Context->hdrs[j]->virtual != -1)
898 menu->current = Context->hdrs[j]->virtual;
899 if (menu->menu == MENU_PAGER) {
900 op = OP_DISPLAY_MESSAGE;
904 menu->redraw = REDRAW_MOTION;
907 mutt_error (_("That message is not visible."));
910 mutt_error (_("Invalid message number."));
914 /* --------------------------------------------------------------------
915 * `index' specific commands
918 case OP_MAIN_DELETE_PATTERN:
925 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
929 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
930 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
934 case OP_MAIN_FETCH_MAIL:
938 menu->redraw = REDRAW_FULL;
944 mutt_help (MENU_MAIN);
945 menu->redraw = REDRAW_FULL;
948 case OP_MAIN_SHOW_LIMIT:
950 if (!Context->pattern)
951 mutt_message (_("No limit pattern is in effect."));
956 /* i18n: ask for a limit to apply */
957 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
958 mutt_message ("%s", buf);
966 menu->oldcurrent = (Context->vcount && menu->current >= 0
968 Context->vcount) ? CURHDR->index : -1;
969 if (op == OP_TOGGLE_READ) {
970 char buf[LONG_STRING];
972 if (!Context->pattern
973 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
974 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
975 Context->pattern ? Context->pattern : ".*");
976 set_option (OPTHIDEREAD);
979 strfcpy (buf, Context->pattern + 8, sizeof (buf));
980 if (!*buf || strncmp (buf, ".*", 2) == 0)
981 snprintf (buf, sizeof (buf), "~A");
982 unset_option (OPTHIDEREAD);
984 FREE (&Context->pattern);
985 Context->pattern = safe_strdup (buf);
987 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
988 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
990 if (menu->oldcurrent >= 0) {
991 /* try to find what used to be the current message */
993 for (i = 0; i < Context->vcount; i++)
994 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
998 if (menu->current < 0)
1003 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1004 if ((Sort & SORT_MASK) == SORT_THREADS)
1005 mutt_draw_tree (Context);
1006 menu->redraw = REDRAW_FULL;
1018 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1021 oldcount = Context ? Context->msgcount : 0;
1024 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1027 if (check == M_NEW_MAIL || check == M_REOPENED)
1028 update_index (menu, Context, check, oldcount, index_hint);
1030 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1031 set_option (OPTSEARCHINVALID);
1038 clearok (stdscr, TRUE);
1039 menu->redraw = REDRAW_FULL;
1043 case OP_SEARCH_REVERSE:
1044 case OP_SEARCH_NEXT:
1045 case OP_SEARCH_OPPOSITE:
1049 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1050 menu->current = menu->oldcurrent;
1052 menu->redraw = REDRAW_MOTION;
1056 case OP_SORT_REVERSE:
1058 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1059 if (Context && Context->msgcount) {
1060 resort_index (menu);
1061 set_option (OPTSEARCHINVALID);
1070 if (tag && !option (OPTAUTOTAG)) {
1071 for (j = 0; j < Context->vcount; j++)
1072 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1073 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1076 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1077 Context->last_tag = CURHDR->tagged ? CURHDR :
1078 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1079 ? NULL : Context->last_tag);
1080 menu->redraw = REDRAW_STATUS;
1081 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1083 menu->redraw |= REDRAW_MOTION_RESYNCH;
1086 menu->redraw |= REDRAW_CURRENT;
1090 case OP_MAIN_TAG_PATTERN:
1094 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1095 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1098 case OP_MAIN_UNDELETE_PATTERN:
1105 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1108 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1110 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1113 case OP_MAIN_UNTAG_PATTERN:
1117 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1118 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1121 /* --------------------------------------------------------------------
1122 * The following operations can be performed inside of the pager.
1126 case OP_MAIN_IMAP_FETCH:
1127 if (Context->magic == M_IMAP)
1128 imap_check_mailbox (Context, &index_hint, 1);
1132 case OP_MAIN_SYNC_FOLDER:
1134 if (Context && !Context->msgcount)
1141 int oldvcount = Context->vcount;
1142 int oldcount = Context->msgcount;
1146 /* calculate the number of messages _above_ the cursor,
1147 * so we can keep the cursor on the current message
1149 for (j = 0; j <= menu->current; j++) {
1150 if (Context->hdrs[Context->v2r[j]]->deleted)
1154 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1155 if (Context->vcount != oldvcount)
1156 menu->current -= dcount;
1157 set_option (OPTSEARCHINVALID);
1159 else if (check == M_NEW_MAIL || check == M_REOPENED)
1160 update_index (menu, Context, check, oldcount, index_hint);
1163 * do a sanity check even if mx_sync_mailbox failed.
1166 if (menu->current < 0 || menu->current >= Context->vcount)
1167 menu->current = ci_first_message ();
1170 /* check for a fatal error, or all messages deleted */
1174 /* if we were in the pager, redisplay the message */
1175 if (menu->menu == MENU_PAGER) {
1176 op = OP_DISPLAY_MESSAGE;
1180 menu->redraw = REDRAW_FULL;
1183 case OP_SIDEBAR_OPEN:
1184 case OP_MAIN_CHANGE_FOLDER:
1185 case OP_MAIN_CHANGE_FOLDER_READONLY:
1187 case OP_MAIN_CHANGE_GROUP:
1188 case OP_MAIN_CHANGE_GROUP_READONLY:
1190 if (attach_msg || option (OPTREADONLY) ||
1192 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1194 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1200 cp = _("Open mailbox in read-only mode");
1202 cp = _("Open mailbox");
1206 unset_option (OPTNEWS);
1207 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1208 set_option (OPTNEWS);
1209 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1212 cp = _("Open newsgroup in read-only mode");
1214 cp = _("Open newsgroup");
1220 if (Context && Context->path)
1221 strncpy (buf, Context->path, sizeof (buf));
1222 mutt_buffy (buf, sizeof (buf));
1225 if (op == OP_SIDEBAR_OPEN) {
1226 strncpy (buf, NONULL(sidebar_get_current ()), sizeof (buf));
1228 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1232 CLEARLINE (LINES - 1);
1237 if (option (OPTNEWS)) {
1238 unset_option (OPTNEWS);
1239 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1243 mutt_expand_path (buf, sizeof (buf));
1244 sidebar_set_current (buf);
1245 if (mx_get_magic (buf) <= 0) {
1246 mutt_error (_("%s is not a mailbox."), buf);
1249 mutt_str_replace (&CurrentFolder, buf);
1254 #ifdef USE_COMPRESSED
1255 if (Context->compressinfo && Context->realpath)
1256 mutt_str_replace (&LastFolder, Context->realpath);
1260 mutt_str_replace (&LastFolder, Context->path);
1261 oldcount = Context ? Context->msgcount : 0;
1263 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1264 if (check == M_NEW_MAIL || check == M_REOPENED)
1265 update_index (menu, Context, check, oldcount, index_hint);
1267 set_option (OPTSEARCHINVALID);
1268 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1276 /* Set CurrentMenu to MENU_MAIN before executing any folder
1277 * hooks so that all the index menu functions are available to
1281 CurrentMenu = MENU_MAIN;
1282 mutt_folder_hook (buf);
1284 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1285 menu->current = ci_first_message ();
1291 /* mutt_buffy_check() must be done with mail-reader mode! */
1292 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1294 && (Context->magic ==
1295 M_NNTP)) ? IndexNewsHelp :
1298 mutt_clear_error ();
1299 mutt_buffy_check (1); /* force the buffy check after we have changed
1301 menu->redraw = REDRAW_FULL;
1302 set_option (OPTSEARCHINVALID);
1305 case OP_DISPLAY_MESSAGE:
1306 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1311 * toggle the weeding of headers so that a user can press the key
1312 * again while reading the message.
1314 if (op == OP_DISPLAY_HEADERS)
1315 toggle_option (OPTWEED);
1317 unset_option (OPTNEEDRESORT);
1319 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1320 mutt_uncollapse_thread (Context, CURHDR);
1321 mutt_set_virtual (Context);
1322 if (option (OPTUNCOLLAPSEJUMP))
1323 menu->current = mutt_thread_next_unread (Context, CURHDR);
1326 if ((op = mutt_display_message (CURHDR)) == -1) {
1327 unset_option (OPTNEEDRESORT);
1331 menu->menu = MENU_PAGER;
1332 menu->oldcurrent = menu->current;
1338 if (menu->menu == MENU_MAIN && attach_msg) {
1343 if ((menu->menu == MENU_MAIN)
1344 && (query_quadoption (OPT_QUIT,
1345 _("Exit Mutt-ng without saving?")) == M_YES))
1348 mx_fastclose_mailbox (Context);
1360 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1361 /* if we were in the pager, redisplay the message */
1362 if (menu->menu == MENU_PAGER) {
1363 op = OP_DISPLAY_MESSAGE;
1367 menu->redraw = REDRAW_CURRENT;
1370 case OP_MAIN_BREAK_THREAD:
1376 if ((Sort & SORT_MASK) != SORT_THREADS)
1377 mutt_error (_("Threading is not enabled."));
1381 HEADER *oldcur = CURHDR;
1383 mutt_break_thread (CURHDR);
1384 mutt_sort_headers (Context, 1);
1385 menu->current = oldcur->virtual;
1388 Context->changed = 1;
1389 mutt_message _("Thread broken");
1391 if (menu->menu == MENU_PAGER) {
1392 op = OP_DISPLAY_MESSAGE;
1396 menu->redraw |= REDRAW_INDEX;
1400 case OP_MAIN_LINK_THREADS:
1406 if ((Sort & SORT_MASK) != SORT_THREADS)
1407 mutt_error (_("Threading is not enabled."));
1409 else if (!CURHDR->env->message_id)
1410 mutt_error (_("No Message-ID: header available to link thread"));
1412 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1413 mutt_error (_("First, please tag a message to be linked here"));
1416 HEADER *oldcur = CURHDR;
1418 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1420 mutt_sort_headers (Context, 1);
1421 menu->current = oldcur->virtual;
1423 Context->changed = 1;
1424 mutt_message _("Threads linked");
1427 mutt_error (_("No thread linked"));
1430 if (menu->menu == MENU_PAGER) {
1431 op = OP_DISPLAY_MESSAGE;
1435 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1438 case OP_MAIN_NEXT_UNDELETED:
1442 if (menu->current >= Context->vcount - 1) {
1443 if (menu->menu == MENU_MAIN)
1444 mutt_error (_("You are on the last message."));
1448 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1449 menu->current = menu->oldcurrent;
1450 if (menu->menu == MENU_MAIN)
1451 mutt_error (_("No undeleted messages."));
1453 else if (menu->menu == MENU_PAGER) {
1454 op = OP_DISPLAY_MESSAGE;
1458 menu->redraw = REDRAW_MOTION;
1465 if (menu->current >= Context->vcount - 1) {
1466 if (menu->menu == MENU_MAIN)
1467 mutt_error (_("You are on the last message."));
1472 if (menu->menu == MENU_PAGER) {
1473 op = OP_DISPLAY_MESSAGE;
1477 menu->redraw = REDRAW_MOTION;
1480 case OP_MAIN_PREV_UNDELETED:
1484 if (menu->current < 1) {
1485 mutt_error (_("You are on the first message."));
1489 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1490 menu->current = menu->oldcurrent;
1491 if (menu->menu == MENU_MAIN)
1492 mutt_error (_("No undeleted messages."));
1494 else if (menu->menu == MENU_PAGER) {
1495 op = OP_DISPLAY_MESSAGE;
1499 menu->redraw = REDRAW_MOTION;
1506 if (menu->current < 1) {
1507 if (menu->menu == MENU_MAIN)
1508 mutt_error (_("You are on the first message."));
1513 if (menu->menu == MENU_PAGER) {
1514 op = OP_DISPLAY_MESSAGE;
1518 menu->redraw = REDRAW_MOTION;
1521 case OP_DECRYPT_COPY:
1522 case OP_DECRYPT_SAVE:
1526 case OP_COPY_MESSAGE:
1528 case OP_DECODE_COPY:
1529 case OP_DECODE_SAVE:
1532 if (mutt_save_message (tag ? NULL : CURHDR,
1533 (op == OP_DECRYPT_SAVE) ||
1534 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1535 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1536 (op == OP_DECRYPT_SAVE)
1537 || (op == OP_DECRYPT_COPY)
1538 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1545 menu->redraw |= REDRAW_INDEX;
1546 else if (option (OPTRESOLVE)) {
1547 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1548 menu->current = menu->oldcurrent;
1549 menu->redraw |= REDRAW_CURRENT;
1552 menu->redraw |= REDRAW_MOTION_RESYNCH;
1555 menu->redraw |= REDRAW_CURRENT;
1559 case OP_MAIN_NEXT_NEW:
1560 case OP_MAIN_NEXT_UNREAD:
1561 case OP_MAIN_PREV_NEW:
1562 case OP_MAIN_PREV_UNREAD:
1563 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1564 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1567 int first_unread = -1;
1575 for (j = 0; j != Context->vcount; j++) {
1576 #define CURHDRi Context->hdrs[Context->v2r[i]]
1577 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1578 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1580 if (i > Context->vcount - 1) {
1581 mutt_message _("Search wrapped to top.");
1589 mutt_message _("Search wrapped to bottom.");
1591 i = Context->vcount - 1;
1595 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1596 if (UNREAD (CURHDRi) && first_unread == -1)
1598 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1601 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1602 if (first_unread == -1)
1604 if ((!CURHDRi->old) && first_new == -1)
1608 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1611 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1612 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1613 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1618 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1619 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1620 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1622 menu->current = first_new;
1623 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1624 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1625 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1626 && first_unread != -1)
1627 menu->current = first_unread;
1629 if (menu->current == -1) {
1630 menu->current = menu->oldcurrent;
1631 mutt_error ("%s%s.",
1632 (op == OP_MAIN_NEXT_NEW
1634 OP_MAIN_PREV_NEW) ? _("No new messages") :
1635 _("No unread messages"),
1636 Context->pattern ? _(" in this limited view") : "");
1638 else if (menu->menu == MENU_PAGER) {
1639 op = OP_DISPLAY_MESSAGE;
1643 menu->redraw = REDRAW_MOTION;
1646 case OP_FLAG_MESSAGE:
1653 if (Context->magic == M_POP) {
1655 mutt_error (_("Can't change 'important' flag on POP server."));
1662 CHECK_IMAP_ACL (IMAP_ACL_WRITE);
1666 if (Context->magic == M_NNTP) {
1668 mutt_error (_("Can't change 'important' flag on NNTP server."));
1675 for (j = 0; j < Context->vcount; j++) {
1676 if (Context->hdrs[Context->v2r[j]]->tagged)
1677 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1678 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1681 menu->redraw |= REDRAW_INDEX;
1684 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1685 if (option (OPTRESOLVE)) {
1686 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1687 menu->current = menu->oldcurrent;
1688 menu->redraw = REDRAW_CURRENT;
1691 menu->redraw = REDRAW_MOTION_RESYNCH;
1694 menu->redraw = REDRAW_CURRENT;
1696 menu->redraw |= REDRAW_STATUS;
1706 CHECK_IMAP_ACL (IMAP_ACL_SEEN);
1710 for (j = 0; j < Context->vcount; j++) {
1711 if (Context->hdrs[Context->v2r[j]]->tagged) {
1712 if (Context->hdrs[Context->v2r[j]]->read ||
1713 Context->hdrs[Context->v2r[j]]->old)
1714 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1717 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1721 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1724 if (CURHDR->read || CURHDR->old)
1725 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1727 mutt_set_flag (Context, CURHDR, M_READ, 1);
1729 if (option (OPTRESOLVE)) {
1730 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1731 menu->current = menu->oldcurrent;
1732 menu->redraw = REDRAW_CURRENT;
1735 menu->redraw = REDRAW_MOTION_RESYNCH;
1738 menu->redraw = REDRAW_CURRENT;
1739 menu->redraw |= REDRAW_STATUS;
1743 case OP_TOGGLE_WRITE:
1746 if (mx_toggle_write (Context) == 0)
1747 menu->redraw |= REDRAW_STATUS;
1750 case OP_MAIN_NEXT_THREAD:
1751 case OP_MAIN_NEXT_SUBTHREAD:
1752 case OP_MAIN_PREV_THREAD:
1753 case OP_MAIN_PREV_SUBTHREAD:
1758 case OP_MAIN_NEXT_THREAD:
1759 menu->current = mutt_next_thread (CURHDR);
1762 case OP_MAIN_NEXT_SUBTHREAD:
1763 menu->current = mutt_next_subthread (CURHDR);
1766 case OP_MAIN_PREV_THREAD:
1767 menu->current = mutt_previous_thread (CURHDR);
1770 case OP_MAIN_PREV_SUBTHREAD:
1771 menu->current = mutt_previous_subthread (CURHDR);
1775 if (menu->current < 0) {
1776 menu->current = menu->oldcurrent;
1777 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1778 mutt_error (_("No more threads."));
1781 mutt_error (_("You are on the first thread."));
1783 else if (menu->menu == MENU_PAGER) {
1784 op = OP_DISPLAY_MESSAGE;
1788 menu->redraw = REDRAW_MOTION;
1791 case OP_MAIN_PARENT_MESSAGE:
1796 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1797 menu->current = menu->oldcurrent;
1799 else if (menu->menu == MENU_PAGER) {
1800 op = OP_DISPLAY_MESSAGE;
1804 menu->redraw = REDRAW_MOTION;
1807 case OP_MAIN_SET_FLAG:
1808 case OP_MAIN_CLEAR_FLAG:
1815 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1818 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1820 menu->redraw = REDRAW_STATUS;
1822 menu->redraw |= REDRAW_INDEX;
1823 else if (option (OPTRESOLVE)) {
1824 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1825 menu->current = menu->oldcurrent;
1826 menu->redraw |= REDRAW_CURRENT;
1829 menu->redraw |= REDRAW_MOTION_RESYNCH;
1832 menu->redraw |= REDRAW_CURRENT;
1836 case OP_MAIN_COLLAPSE_THREAD:
1840 if ((Sort & SORT_MASK) != SORT_THREADS) {
1841 mutt_error (_("Threading is not enabled."));
1846 if (CURHDR->collapsed) {
1847 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1848 mutt_set_virtual (Context);
1849 if (option (OPTUNCOLLAPSEJUMP))
1850 menu->current = mutt_thread_next_unread (Context, CURHDR);
1852 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1853 menu->current = mutt_collapse_thread (Context, CURHDR);
1854 mutt_set_virtual (Context);
1857 mutt_error (_("Thread contains unread messages."));
1862 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1866 case OP_MAIN_COLLAPSE_ALL:
1870 if ((Sort & SORT_MASK) != SORT_THREADS) {
1871 mutt_error (_("Threading is not enabled."));
1878 THREAD *thread, *top;
1881 if (CURHDR->collapsed)
1882 final = mutt_uncollapse_thread (Context, CURHDR);
1883 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1884 final = mutt_collapse_thread (Context, CURHDR);
1886 final = CURHDR->virtual;
1888 base = Context->hdrs[Context->v2r[final]];
1890 top = Context->tree;
1891 Context->collapsed = !Context->collapsed;
1892 while ((thread = top) != NULL) {
1893 while (!thread->message)
1894 thread = thread->child;
1895 h = thread->message;
1897 if (h->collapsed != Context->collapsed) {
1899 mutt_uncollapse_thread (Context, h);
1900 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1901 mutt_collapse_thread (Context, h);
1906 mutt_set_virtual (Context);
1907 for (j = 0; j < Context->vcount; j++) {
1908 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1914 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1918 /* --------------------------------------------------------------------
1919 * These functions are invoked directly from the internal-pager
1922 case OP_BOUNCE_MESSAGE:
1927 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1930 case OP_CREATE_ALIAS:
1932 mutt_create_alias (Context
1933 && Context->vcount ? CURHDR->env : NULL, NULL);
1934 MAYBE_REDRAW (menu->redraw);
1935 menu->redraw |= REDRAW_CURRENT;
1940 mutt_query_menu (NULL, 0);
1941 MAYBE_REDRAW (menu->redraw);
1944 case OP_PURGE_MESSAGE:
1952 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1956 mutt_tag_set_flag (M_DELETE, 1);
1957 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1958 if (option (OPTDELETEUNTAG))
1959 mutt_tag_set_flag (M_TAG, 0);
1960 menu->redraw = REDRAW_INDEX;
1963 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1964 mutt_set_flag (Context, CURHDR, M_PURGED,
1965 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1966 if (option (OPTDELETEUNTAG))
1967 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1968 if (option (OPTRESOLVE)) {
1969 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1970 menu->current = menu->oldcurrent;
1971 menu->redraw = REDRAW_CURRENT;
1973 else if (menu->menu == MENU_PAGER) {
1974 op = OP_DISPLAY_MESSAGE;
1978 menu->redraw |= REDRAW_MOTION_RESYNCH;
1981 menu->redraw = REDRAW_CURRENT;
1983 menu->redraw |= REDRAW_STATUS;
1986 case OP_DELETE_THREAD:
1987 case OP_DELETE_SUBTHREAD:
1994 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1997 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1998 op == OP_DELETE_THREAD ? 0 : 1);
2001 if (option (OPTDELETEUNTAG))
2002 mutt_thread_set_flag (CURHDR, M_TAG, 0,
2003 op == OP_DELETE_THREAD ? 0 : 1);
2004 if (option (OPTRESOLVE))
2005 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
2006 menu->current = menu->oldcurrent;
2007 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2013 if (Context && Context->magic == M_NNTP) {
2014 if (mutt_newsgroup_catchup (CurrentNewsSrv,
2015 ((NNTP_DATA *) Context->data)->group))
2016 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2021 case OP_DISPLAY_ADDRESS:
2025 mutt_display_address (CURHDR->env);
2028 case OP_ENTER_COMMAND:
2030 CurrentMenu = MENU_MAIN;
2031 mutt_enter_command ();
2032 mutt_check_rescore (Context);
2033 if (option (OPTFORCEREDRAWINDEX))
2034 menu->redraw = REDRAW_FULL;
2035 unset_option (OPTFORCEREDRAWINDEX);
2036 unset_option (OPTFORCEREDRAWPAGER);
2039 case OP_EDIT_MESSAGE:
2047 if (Context->magic == M_POP) {
2049 mutt_error (_("Can't edit message on POP server."));
2056 CHECK_IMAP_ACL (IMAP_ACL_INSERT);
2060 if (Context->magic == M_NNTP) {
2062 mutt_error (_("Can't edit message on newsserver."));
2068 if (option (OPTPGPAUTODEC)
2069 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2070 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2071 mutt_edit_message (Context, tag ? NULL : CURHDR);
2072 menu->redraw = REDRAW_FULL;
2076 case OP_FORWARD_MESSAGE:
2081 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2082 menu->redraw = REDRAW_FULL;
2086 case OP_FORGET_PASSPHRASE:
2087 crypt_forget_passphrase ();
2090 case OP_GROUP_REPLY:
2095 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2096 tag ? NULL : CURHDR);
2097 menu->redraw = REDRAW_FULL;
2105 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2106 tag ? NULL : CURHDR);
2107 menu->redraw = REDRAW_FULL;
2113 ci_send_message (0, NULL, NULL, Context, NULL);
2114 menu->redraw = REDRAW_FULL;
2118 if (!(WithCrypto & APPLICATION_PGP))
2121 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2122 menu->redraw = REDRAW_FULL;
2126 case OP_EXTRACT_KEYS:
2131 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2132 menu->redraw = REDRAW_FULL;
2136 case OP_CHECK_TRADITIONAL:
2137 if (!(WithCrypto & APPLICATION_PGP))
2141 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2142 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2144 if (menu->menu == MENU_PAGER) {
2145 op = OP_DISPLAY_MESSAGE;
2154 mutt_pipe_message (tag ? NULL : CURHDR);
2155 MAYBE_REDRAW (menu->redraw);
2162 mutt_print_message (tag ? NULL : CURHDR);
2165 case OP_MAIN_READ_THREAD:
2166 case OP_MAIN_READ_SUBTHREAD:
2173 CHECK_IMAP_ACL (IMAP_ACL_SEEN);
2176 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2177 op == OP_MAIN_READ_THREAD ? 0 : 1);
2180 if (option (OPTRESOLVE)) {
2181 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2182 mutt_next_thread (CURHDR) :
2183 mutt_next_subthread (CURHDR))) == -1)
2184 menu->current = menu->oldcurrent;
2186 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2190 case OP_RECALL_MESSAGE:
2193 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2194 menu->redraw = REDRAW_FULL;
2204 for (j = 0; j < Context->vcount; j++) {
2205 if (Context->hdrs[Context->v2r[j]]->tagged)
2206 mutt_resend_message (NULL, Context,
2207 Context->hdrs[Context->v2r[j]]);
2211 mutt_resend_message (NULL, Context, CURHDR);
2213 menu->redraw = REDRAW_FULL;
2219 case OP_FORWARD_TO_GROUP:
2222 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2223 Context && Context->msgcount == 0) {
2224 mutt_error (_("There are no messages."));
2227 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2228 mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2229 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2230 _("Reply by mail as poster prefers?")) !=
2232 if (Context && Context->magic == M_NNTP
2233 && !((NNTP_DATA *) Context->data)->allowed
2234 && query_quadoption (OPT_TOMODERATED,
2236 ("Posting to this group not allowed, may be moderated. Continue?"))
2240 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2243 if (op == OP_FOLLOWUP)
2244 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2245 tag ? NULL : CURHDR);
2247 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2248 tag ? NULL : CURHDR);
2250 menu->redraw = REDRAW_FULL;
2260 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2261 menu->redraw = REDRAW_FULL;
2264 case OP_SHELL_ESCAPE:
2266 mutt_shell_escape ();
2267 MAYBE_REDRAW (menu->redraw);
2271 case OP_TAG_SUBTHREAD:
2275 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2276 op == OP_TAG_THREAD ? 0 : 1);
2279 if (option (OPTRESOLVE)) {
2280 menu->current = mutt_next_thread (CURHDR);
2282 if (menu->current == -1)
2283 menu->current = menu->oldcurrent;
2285 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2296 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2300 mutt_tag_set_flag (M_DELETE, 0);
2301 mutt_tag_set_flag (M_PURGED, 0);
2302 menu->redraw = REDRAW_INDEX;
2305 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2306 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2307 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2309 menu->redraw = REDRAW_MOTION_RESYNCH;
2312 menu->redraw = REDRAW_CURRENT;
2314 menu->redraw |= REDRAW_STATUS;
2317 case OP_UNDELETE_THREAD:
2318 case OP_UNDELETE_SUBTHREAD:
2325 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2328 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2329 op == OP_UNDELETE_THREAD ? 0 : 1)
2330 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2331 op == OP_UNDELETE_THREAD ? 0 : 1);
2334 if (option (OPTRESOLVE)) {
2335 if (op == OP_UNDELETE_THREAD)
2336 menu->current = mutt_next_thread (CURHDR);
2338 menu->current = mutt_next_subthread (CURHDR);
2340 if (menu->current == -1)
2341 menu->current = menu->oldcurrent;
2343 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2353 menu->redraw = REDRAW_FULL;
2356 case OP_VIEW_ATTACHMENTS:
2359 mutt_view_attachments (CURHDR);
2360 if (CURHDR->attach_del)
2361 Context->changed = 1;
2362 menu->redraw = REDRAW_FULL;
2372 case OP_SIDEBAR_SCROLL_UP:
2373 case OP_SIDEBAR_SCROLL_DOWN:
2374 case OP_SIDEBAR_NEXT:
2375 case OP_SIDEBAR_PREV:
2376 case OP_SIDEBAR_NEXT_NEW:
2377 case OP_SIDEBAR_PREV_NEW:
2378 sidebar_scroll (op, menu->menu);
2381 if (menu->menu == MENU_MAIN)
2382 km_error_key (MENU_MAIN);
2385 if (menu->menu == MENU_PAGER) {
2386 menu->menu = MENU_MAIN;
2387 menu->redraw = REDRAW_FULL;
2389 set_option (OPTWEED); /* turn header weeding back on. */
2398 /* Close all open IMAP connections */
2403 /* Close all open NNTP connections */
2408 mutt_menuDestroy (&menu);
2412 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2419 for (color = ColorIndexList; color; color = color->next)
2420 if (mutt_pattern_exec
2421 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2422 curhdr->pair = color->pair;
2425 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];