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 set_curbuffy (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 draw_sidebar (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 draw_sidebar (menu->menu);
560 if (menu->redraw & REDRAW_FULL) {
561 menu_redraw_full (menu);
562 draw_sidebar (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 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) {
1228 strncpy (buf, CurBuffy->path, sizeof (buf));
1230 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1234 CLEARLINE (LINES - 1);
1239 if (option (OPTNEWS)) {
1240 unset_option (OPTNEWS);
1241 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1245 mutt_expand_path (buf, sizeof (buf));
1247 if (mx_get_magic (buf) <= 0) {
1248 mutt_error (_("%s is not a mailbox."), buf);
1251 mutt_str_replace (&CurrentFolder, buf);
1256 #ifdef USE_COMPRESSED
1257 if (Context->compressinfo && Context->realpath)
1258 mutt_str_replace (&LastFolder, Context->realpath);
1262 mutt_str_replace (&LastFolder, Context->path);
1263 oldcount = Context ? Context->msgcount : 0;
1265 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1266 if (check == M_NEW_MAIL || check == M_REOPENED)
1267 update_index (menu, Context, check, oldcount, index_hint);
1269 set_option (OPTSEARCHINVALID);
1270 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1278 /* Set CurrentMenu to MENU_MAIN before executing any folder
1279 * hooks so that all the index menu functions are available to
1283 CurrentMenu = MENU_MAIN;
1284 mutt_folder_hook (buf);
1286 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1287 menu->current = ci_first_message ();
1293 /* mutt_buffy_check() must be done with mail-reader mode! */
1294 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1296 && (Context->magic ==
1297 M_NNTP)) ? IndexNewsHelp :
1300 mutt_clear_error ();
1301 mutt_buffy_check (1); /* force the buffy check after we have changed
1303 menu->redraw = REDRAW_FULL;
1304 set_option (OPTSEARCHINVALID);
1307 case OP_DISPLAY_MESSAGE:
1308 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1313 * toggle the weeding of headers so that a user can press the key
1314 * again while reading the message.
1316 if (op == OP_DISPLAY_HEADERS)
1317 toggle_option (OPTWEED);
1319 unset_option (OPTNEEDRESORT);
1321 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1322 mutt_uncollapse_thread (Context, CURHDR);
1323 mutt_set_virtual (Context);
1324 if (option (OPTUNCOLLAPSEJUMP))
1325 menu->current = mutt_thread_next_unread (Context, CURHDR);
1328 if ((op = mutt_display_message (CURHDR)) == -1) {
1329 unset_option (OPTNEEDRESORT);
1333 menu->menu = MENU_PAGER;
1334 menu->oldcurrent = menu->current;
1340 if (menu->menu == MENU_MAIN && attach_msg) {
1345 if ((menu->menu == MENU_MAIN)
1346 && (query_quadoption (OPT_QUIT,
1347 _("Exit Mutt-ng without saving?")) == M_YES))
1350 mx_fastclose_mailbox (Context);
1362 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1363 /* if we were in the pager, redisplay the message */
1364 if (menu->menu == MENU_PAGER) {
1365 op = OP_DISPLAY_MESSAGE;
1369 menu->redraw = REDRAW_CURRENT;
1372 case OP_MAIN_BREAK_THREAD:
1378 if ((Sort & SORT_MASK) != SORT_THREADS)
1379 mutt_error (_("Threading is not enabled."));
1383 HEADER *oldcur = CURHDR;
1385 mutt_break_thread (CURHDR);
1386 mutt_sort_headers (Context, 1);
1387 menu->current = oldcur->virtual;
1390 Context->changed = 1;
1391 mutt_message _("Thread broken");
1393 if (menu->menu == MENU_PAGER) {
1394 op = OP_DISPLAY_MESSAGE;
1398 menu->redraw |= REDRAW_INDEX;
1402 case OP_MAIN_LINK_THREADS:
1408 if ((Sort & SORT_MASK) != SORT_THREADS)
1409 mutt_error (_("Threading is not enabled."));
1411 else if (!CURHDR->env->message_id)
1412 mutt_error (_("No Message-ID: header available to link thread"));
1414 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1415 mutt_error (_("First, please tag a message to be linked here"));
1418 HEADER *oldcur = CURHDR;
1420 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1422 mutt_sort_headers (Context, 1);
1423 menu->current = oldcur->virtual;
1425 Context->changed = 1;
1426 mutt_message _("Threads linked");
1429 mutt_error (_("No thread linked"));
1432 if (menu->menu == MENU_PAGER) {
1433 op = OP_DISPLAY_MESSAGE;
1437 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1440 case OP_MAIN_NEXT_UNDELETED:
1444 if (menu->current >= Context->vcount - 1) {
1445 if (menu->menu == MENU_MAIN)
1446 mutt_error (_("You are on the last message."));
1450 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1451 menu->current = menu->oldcurrent;
1452 if (menu->menu == MENU_MAIN)
1453 mutt_error (_("No undeleted messages."));
1455 else if (menu->menu == MENU_PAGER) {
1456 op = OP_DISPLAY_MESSAGE;
1460 menu->redraw = REDRAW_MOTION;
1467 if (menu->current >= Context->vcount - 1) {
1468 if (menu->menu == MENU_MAIN)
1469 mutt_error (_("You are on the last message."));
1474 if (menu->menu == MENU_PAGER) {
1475 op = OP_DISPLAY_MESSAGE;
1479 menu->redraw = REDRAW_MOTION;
1482 case OP_MAIN_PREV_UNDELETED:
1486 if (menu->current < 1) {
1487 mutt_error (_("You are on the first message."));
1491 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1492 menu->current = menu->oldcurrent;
1493 if (menu->menu == MENU_MAIN)
1494 mutt_error (_("No undeleted messages."));
1496 else if (menu->menu == MENU_PAGER) {
1497 op = OP_DISPLAY_MESSAGE;
1501 menu->redraw = REDRAW_MOTION;
1508 if (menu->current < 1) {
1509 if (menu->menu == MENU_MAIN)
1510 mutt_error (_("You are on the first message."));
1515 if (menu->menu == MENU_PAGER) {
1516 op = OP_DISPLAY_MESSAGE;
1520 menu->redraw = REDRAW_MOTION;
1523 case OP_DECRYPT_COPY:
1524 case OP_DECRYPT_SAVE:
1528 case OP_COPY_MESSAGE:
1530 case OP_DECODE_COPY:
1531 case OP_DECODE_SAVE:
1534 if (mutt_save_message (tag ? NULL : CURHDR,
1535 (op == OP_DECRYPT_SAVE) ||
1536 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1537 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1538 (op == OP_DECRYPT_SAVE)
1539 || (op == OP_DECRYPT_COPY)
1540 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1547 menu->redraw |= REDRAW_INDEX;
1548 else if (option (OPTRESOLVE)) {
1549 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1550 menu->current = menu->oldcurrent;
1551 menu->redraw |= REDRAW_CURRENT;
1554 menu->redraw |= REDRAW_MOTION_RESYNCH;
1557 menu->redraw |= REDRAW_CURRENT;
1561 case OP_MAIN_NEXT_NEW:
1562 case OP_MAIN_NEXT_UNREAD:
1563 case OP_MAIN_PREV_NEW:
1564 case OP_MAIN_PREV_UNREAD:
1565 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1566 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1569 int first_unread = -1;
1577 for (j = 0; j != Context->vcount; j++) {
1578 #define CURHDRi Context->hdrs[Context->v2r[i]]
1579 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1580 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1582 if (i > Context->vcount - 1) {
1583 mutt_message _("Search wrapped to top.");
1591 mutt_message _("Search wrapped to bottom.");
1593 i = Context->vcount - 1;
1597 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1598 if (UNREAD (CURHDRi) && first_unread == -1)
1600 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1603 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1604 if (first_unread == -1)
1606 if ((!CURHDRi->old) && first_new == -1)
1610 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1613 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1614 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1615 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1620 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1621 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1622 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1624 menu->current = first_new;
1625 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1626 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1627 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1628 && first_unread != -1)
1629 menu->current = first_unread;
1631 if (menu->current == -1) {
1632 menu->current = menu->oldcurrent;
1633 mutt_error ("%s%s.",
1634 (op == OP_MAIN_NEXT_NEW
1636 OP_MAIN_PREV_NEW) ? _("No new messages") :
1637 _("No unread messages"),
1638 Context->pattern ? _(" in this limited view") : "");
1640 else if (menu->menu == MENU_PAGER) {
1641 op = OP_DISPLAY_MESSAGE;
1645 menu->redraw = REDRAW_MOTION;
1648 case OP_FLAG_MESSAGE:
1655 if (Context->magic == M_POP) {
1657 mutt_error (_("Can't change 'important' flag on POP server."));
1664 CHECK_IMAP_ACL (IMAP_ACL_WRITE);
1668 if (Context->magic == M_NNTP) {
1670 mutt_error (_("Can't change 'important' flag on NNTP server."));
1677 for (j = 0; j < Context->vcount; j++) {
1678 if (Context->hdrs[Context->v2r[j]]->tagged)
1679 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1680 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1683 menu->redraw |= REDRAW_INDEX;
1686 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1687 if (option (OPTRESOLVE)) {
1688 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1689 menu->current = menu->oldcurrent;
1690 menu->redraw = REDRAW_CURRENT;
1693 menu->redraw = REDRAW_MOTION_RESYNCH;
1696 menu->redraw = REDRAW_CURRENT;
1698 menu->redraw |= REDRAW_STATUS;
1708 CHECK_IMAP_ACL (IMAP_ACL_SEEN);
1712 for (j = 0; j < Context->vcount; j++) {
1713 if (Context->hdrs[Context->v2r[j]]->tagged) {
1714 if (Context->hdrs[Context->v2r[j]]->read ||
1715 Context->hdrs[Context->v2r[j]]->old)
1716 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1719 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1723 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1726 if (CURHDR->read || CURHDR->old)
1727 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1729 mutt_set_flag (Context, CURHDR, M_READ, 1);
1731 if (option (OPTRESOLVE)) {
1732 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1733 menu->current = menu->oldcurrent;
1734 menu->redraw = REDRAW_CURRENT;
1737 menu->redraw = REDRAW_MOTION_RESYNCH;
1740 menu->redraw = REDRAW_CURRENT;
1741 menu->redraw |= REDRAW_STATUS;
1745 case OP_TOGGLE_WRITE:
1748 if (mx_toggle_write (Context) == 0)
1749 menu->redraw |= REDRAW_STATUS;
1752 case OP_MAIN_NEXT_THREAD:
1753 case OP_MAIN_NEXT_SUBTHREAD:
1754 case OP_MAIN_PREV_THREAD:
1755 case OP_MAIN_PREV_SUBTHREAD:
1760 case OP_MAIN_NEXT_THREAD:
1761 menu->current = mutt_next_thread (CURHDR);
1764 case OP_MAIN_NEXT_SUBTHREAD:
1765 menu->current = mutt_next_subthread (CURHDR);
1768 case OP_MAIN_PREV_THREAD:
1769 menu->current = mutt_previous_thread (CURHDR);
1772 case OP_MAIN_PREV_SUBTHREAD:
1773 menu->current = mutt_previous_subthread (CURHDR);
1777 if (menu->current < 0) {
1778 menu->current = menu->oldcurrent;
1779 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1780 mutt_error (_("No more threads."));
1783 mutt_error (_("You are on the first thread."));
1785 else if (menu->menu == MENU_PAGER) {
1786 op = OP_DISPLAY_MESSAGE;
1790 menu->redraw = REDRAW_MOTION;
1793 case OP_MAIN_PARENT_MESSAGE:
1798 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1799 menu->current = menu->oldcurrent;
1801 else if (menu->menu == MENU_PAGER) {
1802 op = OP_DISPLAY_MESSAGE;
1806 menu->redraw = REDRAW_MOTION;
1809 case OP_MAIN_SET_FLAG:
1810 case OP_MAIN_CLEAR_FLAG:
1817 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1820 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1822 menu->redraw = REDRAW_STATUS;
1824 menu->redraw |= REDRAW_INDEX;
1825 else if (option (OPTRESOLVE)) {
1826 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1827 menu->current = menu->oldcurrent;
1828 menu->redraw |= REDRAW_CURRENT;
1831 menu->redraw |= REDRAW_MOTION_RESYNCH;
1834 menu->redraw |= REDRAW_CURRENT;
1838 case OP_MAIN_COLLAPSE_THREAD:
1842 if ((Sort & SORT_MASK) != SORT_THREADS) {
1843 mutt_error (_("Threading is not enabled."));
1848 if (CURHDR->collapsed) {
1849 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1850 mutt_set_virtual (Context);
1851 if (option (OPTUNCOLLAPSEJUMP))
1852 menu->current = mutt_thread_next_unread (Context, CURHDR);
1854 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1855 menu->current = mutt_collapse_thread (Context, CURHDR);
1856 mutt_set_virtual (Context);
1859 mutt_error (_("Thread contains unread messages."));
1864 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1868 case OP_MAIN_COLLAPSE_ALL:
1872 if ((Sort & SORT_MASK) != SORT_THREADS) {
1873 mutt_error (_("Threading is not enabled."));
1880 THREAD *thread, *top;
1883 if (CURHDR->collapsed)
1884 final = mutt_uncollapse_thread (Context, CURHDR);
1885 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1886 final = mutt_collapse_thread (Context, CURHDR);
1888 final = CURHDR->virtual;
1890 base = Context->hdrs[Context->v2r[final]];
1892 top = Context->tree;
1893 Context->collapsed = !Context->collapsed;
1894 while ((thread = top) != NULL) {
1895 while (!thread->message)
1896 thread = thread->child;
1897 h = thread->message;
1899 if (h->collapsed != Context->collapsed) {
1901 mutt_uncollapse_thread (Context, h);
1902 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1903 mutt_collapse_thread (Context, h);
1908 mutt_set_virtual (Context);
1909 for (j = 0; j < Context->vcount; j++) {
1910 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1916 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1920 /* --------------------------------------------------------------------
1921 * These functions are invoked directly from the internal-pager
1924 case OP_BOUNCE_MESSAGE:
1929 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1932 case OP_CREATE_ALIAS:
1934 mutt_create_alias (Context
1935 && Context->vcount ? CURHDR->env : NULL, NULL);
1936 MAYBE_REDRAW (menu->redraw);
1937 menu->redraw |= REDRAW_CURRENT;
1942 mutt_query_menu (NULL, 0);
1943 MAYBE_REDRAW (menu->redraw);
1946 case OP_PURGE_MESSAGE:
1954 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1958 mutt_tag_set_flag (M_DELETE, 1);
1959 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1960 if (option (OPTDELETEUNTAG))
1961 mutt_tag_set_flag (M_TAG, 0);
1962 menu->redraw = REDRAW_INDEX;
1965 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1966 mutt_set_flag (Context, CURHDR, M_PURGED,
1967 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1968 if (option (OPTDELETEUNTAG))
1969 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1970 if (option (OPTRESOLVE)) {
1971 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1972 menu->current = menu->oldcurrent;
1973 menu->redraw = REDRAW_CURRENT;
1975 else if (menu->menu == MENU_PAGER) {
1976 op = OP_DISPLAY_MESSAGE;
1980 menu->redraw |= REDRAW_MOTION_RESYNCH;
1983 menu->redraw = REDRAW_CURRENT;
1985 menu->redraw |= REDRAW_STATUS;
1988 case OP_DELETE_THREAD:
1989 case OP_DELETE_SUBTHREAD:
1996 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1999 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
2000 op == OP_DELETE_THREAD ? 0 : 1);
2003 if (option (OPTDELETEUNTAG))
2004 mutt_thread_set_flag (CURHDR, M_TAG, 0,
2005 op == OP_DELETE_THREAD ? 0 : 1);
2006 if (option (OPTRESOLVE))
2007 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
2008 menu->current = menu->oldcurrent;
2009 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2015 if (Context && Context->magic == M_NNTP) {
2016 if (mutt_newsgroup_catchup (CurrentNewsSrv,
2017 ((NNTP_DATA *) Context->data)->group))
2018 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2023 case OP_DISPLAY_ADDRESS:
2027 mutt_display_address (CURHDR->env);
2030 case OP_ENTER_COMMAND:
2032 CurrentMenu = MENU_MAIN;
2033 mutt_enter_command ();
2034 mutt_check_rescore (Context);
2035 if (option (OPTFORCEREDRAWINDEX))
2036 menu->redraw = REDRAW_FULL;
2037 unset_option (OPTFORCEREDRAWINDEX);
2038 unset_option (OPTFORCEREDRAWPAGER);
2041 case OP_EDIT_MESSAGE:
2049 if (Context->magic == M_POP) {
2051 mutt_error (_("Can't edit message on POP server."));
2058 CHECK_IMAP_ACL (IMAP_ACL_INSERT);
2062 if (Context->magic == M_NNTP) {
2064 mutt_error (_("Can't edit message on newsserver."));
2070 if (option (OPTPGPAUTODEC)
2071 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2072 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2073 mutt_edit_message (Context, tag ? NULL : CURHDR);
2074 menu->redraw = REDRAW_FULL;
2078 case OP_FORWARD_MESSAGE:
2083 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2084 menu->redraw = REDRAW_FULL;
2088 case OP_FORGET_PASSPHRASE:
2089 crypt_forget_passphrase ();
2092 case OP_GROUP_REPLY:
2097 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2098 tag ? NULL : CURHDR);
2099 menu->redraw = REDRAW_FULL;
2107 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2108 tag ? NULL : CURHDR);
2109 menu->redraw = REDRAW_FULL;
2115 ci_send_message (0, NULL, NULL, Context, NULL);
2116 menu->redraw = REDRAW_FULL;
2120 if (!(WithCrypto & APPLICATION_PGP))
2123 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2124 menu->redraw = REDRAW_FULL;
2128 case OP_EXTRACT_KEYS:
2133 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2134 menu->redraw = REDRAW_FULL;
2138 case OP_CHECK_TRADITIONAL:
2139 if (!(WithCrypto & APPLICATION_PGP))
2143 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2144 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2146 if (menu->menu == MENU_PAGER) {
2147 op = OP_DISPLAY_MESSAGE;
2156 mutt_pipe_message (tag ? NULL : CURHDR);
2157 MAYBE_REDRAW (menu->redraw);
2164 mutt_print_message (tag ? NULL : CURHDR);
2167 case OP_MAIN_READ_THREAD:
2168 case OP_MAIN_READ_SUBTHREAD:
2175 CHECK_IMAP_ACL (IMAP_ACL_SEEN);
2178 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2179 op == OP_MAIN_READ_THREAD ? 0 : 1);
2182 if (option (OPTRESOLVE)) {
2183 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2184 mutt_next_thread (CURHDR) :
2185 mutt_next_subthread (CURHDR))) == -1)
2186 menu->current = menu->oldcurrent;
2188 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2192 case OP_RECALL_MESSAGE:
2195 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2196 menu->redraw = REDRAW_FULL;
2206 for (j = 0; j < Context->vcount; j++) {
2207 if (Context->hdrs[Context->v2r[j]]->tagged)
2208 mutt_resend_message (NULL, Context,
2209 Context->hdrs[Context->v2r[j]]);
2213 mutt_resend_message (NULL, Context, CURHDR);
2215 menu->redraw = REDRAW_FULL;
2221 case OP_FORWARD_TO_GROUP:
2224 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2225 Context && Context->msgcount == 0) {
2226 mutt_error (_("There are no messages."));
2229 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2230 mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2231 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2232 _("Reply by mail as poster prefers?")) !=
2234 if (Context && Context->magic == M_NNTP
2235 && !((NNTP_DATA *) Context->data)->allowed
2236 && query_quadoption (OPT_TOMODERATED,
2238 ("Posting to this group not allowed, may be moderated. Continue?"))
2242 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2245 if (op == OP_FOLLOWUP)
2246 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2247 tag ? NULL : CURHDR);
2249 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2250 tag ? NULL : CURHDR);
2252 menu->redraw = REDRAW_FULL;
2262 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2263 menu->redraw = REDRAW_FULL;
2266 case OP_SHELL_ESCAPE:
2268 mutt_shell_escape ();
2269 MAYBE_REDRAW (menu->redraw);
2273 case OP_TAG_SUBTHREAD:
2277 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2278 op == OP_TAG_THREAD ? 0 : 1);
2281 if (option (OPTRESOLVE)) {
2282 menu->current = mutt_next_thread (CURHDR);
2284 if (menu->current == -1)
2285 menu->current = menu->oldcurrent;
2287 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2298 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2302 mutt_tag_set_flag (M_DELETE, 0);
2303 mutt_tag_set_flag (M_PURGED, 0);
2304 menu->redraw = REDRAW_INDEX;
2307 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2308 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2309 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2311 menu->redraw = REDRAW_MOTION_RESYNCH;
2314 menu->redraw = REDRAW_CURRENT;
2316 menu->redraw |= REDRAW_STATUS;
2319 case OP_UNDELETE_THREAD:
2320 case OP_UNDELETE_SUBTHREAD:
2327 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2330 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2331 op == OP_UNDELETE_THREAD ? 0 : 1)
2332 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2333 op == OP_UNDELETE_THREAD ? 0 : 1);
2336 if (option (OPTRESOLVE)) {
2337 if (op == OP_UNDELETE_THREAD)
2338 menu->current = mutt_next_thread (CURHDR);
2340 menu->current = mutt_next_subthread (CURHDR);
2342 if (menu->current == -1)
2343 menu->current = menu->oldcurrent;
2345 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2355 menu->redraw = REDRAW_FULL;
2358 case OP_VIEW_ATTACHMENTS:
2361 mutt_view_attachments (CURHDR);
2362 if (CURHDR->attach_del)
2363 Context->changed = 1;
2364 menu->redraw = REDRAW_FULL;
2374 case OP_SIDEBAR_SCROLL_UP:
2375 case OP_SIDEBAR_SCROLL_DOWN:
2376 case OP_SIDEBAR_NEXT:
2377 case OP_SIDEBAR_PREV:
2378 case OP_SIDEBAR_NEXT_NEW:
2379 case OP_SIDEBAR_PREV_NEW:
2380 scroll_sidebar (op, menu->menu);
2383 if (menu->menu == MENU_MAIN)
2384 km_error_key (MENU_MAIN);
2387 if (menu->menu == MENU_PAGER) {
2388 menu->menu = MENU_MAIN;
2389 menu->redraw = REDRAW_FULL;
2391 set_option (OPTWEED); /* turn header weeding back on. */
2400 /* Close all open IMAP connections */
2405 /* Close all open NNTP connections */
2410 mutt_menuDestroy (&menu);
2414 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2421 for (color = ColorIndexList; color; color = color->next)
2422 if (mutt_pattern_exec
2423 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2424 curhdr->pair = color->pair;
2427 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];