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"
51 static const char *No_mailbox_is_open = N_("No mailbox is open.");
52 static const char *There_are_no_messages = N_("There are no messages.");
53 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
54 static const char *Function_not_permitted_in_attach_message_mode =
55 N_("Function not permitted in attach-message mode.");
56 static const char *No_visible = N_("No visible messages.");
58 #define CHECK_MSGCOUNT if (!Context) \
61 mutt_error(_(No_mailbox_is_open)); \
64 else if (!Context->msgcount) \
67 mutt_error(_(There_are_no_messages)); \
71 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
74 mutt_error(_(No_visible)); \
79 #define CHECK_READONLY if (Context->readonly) \
82 mutt_error(_(Mailbox_is_read_only)); \
87 /* the error message returned here could be better. */
88 #define CHECK_IMAP_ACL(aclbit) if (Context->magic == M_IMAP) \
89 if (mutt_bit_isset (((IMAP_DATA *)Context->data)->capabilities, ACL) \
90 && !mutt_bit_isset(((IMAP_DATA *)Context->data)->rights,aclbit)){ \
92 mutt_error ("Operation not permitted by the IMAP ACL for this mailbox"); \
97 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
100 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
104 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
105 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
106 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
108 extern const char *ReleaseDate;
109 extern size_t UngetCount;
111 static void set_xterm_title_bar (char *title)
113 fputs ("\033]2;", stdout);
114 fputs (title, stdout);
115 fputs ("\007", stdout);
119 static void set_xterm_icon_name (char *name)
121 fputs ("\033]1;", stdout);
122 fputs (name, stdout);
123 fputs ("\007", stdout);
127 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
130 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
131 int edgemsgno, reverse = Sort & SORT_REVERSE;
132 HEADER *h = Context->hdrs[Context->v2r[num]];
135 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
136 flag |= M_FORMAT_TREE; /* display the thread tree */
137 if (h->display_subject)
138 flag |= M_FORMAT_FORCESUBJ;
141 if (menu->top + menu->pagelen > menu->max)
142 edgemsgno = Context->v2r[menu->max - 1];
144 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
147 edgemsgno = Context->v2r[menu->top];
149 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
153 /* if no ancestor is visible on current screen, provisionally force
155 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
157 flag |= M_FORMAT_FORCESUBJ;
160 else if (tmp->message->virtual >= 0)
163 if (flag & M_FORMAT_FORCESUBJ) {
164 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
168 /* ...but if a previous sibling is available, don't force it */
169 if (reverse ? tmp->message->msgno >
170 edgemsgno : tmp->message->msgno < edgemsgno)
172 else if (tmp->message->virtual >= 0) {
173 flag &= ~M_FORMAT_FORCESUBJ;
181 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
184 int index_color (int index_no)
186 HEADER *h = Context->hdrs[Context->v2r[index_no]];
191 mutt_set_header_color (Context, h);
195 static int ci_next_undeleted (int msgno)
199 for (i = msgno + 1; i < Context->vcount; i++)
200 if (!Context->hdrs[Context->v2r[i]]->deleted)
205 static int ci_previous_undeleted (int msgno)
209 for (i = msgno - 1; i >= 0; i--)
210 if (!Context->hdrs[Context->v2r[i]]->deleted)
215 /* Return the index of the first new message, or failing that, the first
218 static int ci_first_message (void)
222 if (Context && Context->msgcount) {
223 for (i = 0; i < Context->vcount; i++) {
224 if (!Context->hdrs[Context->v2r[i]]->read &&
225 !Context->hdrs[Context->v2r[i]]->deleted) {
226 if (!Context->hdrs[Context->v2r[i]]->old)
235 /* If Sort is reverse and not threaded, the latest message is first.
236 * If Sort is threaded, the latest message is first iff exactly one
237 * of Sort and SortAux are reverse.
239 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
240 ((Sort & SORT_MASK) == SORT_THREADS &&
241 ((Sort ^ SortAux) & SORT_REVERSE)))
244 return (Context->vcount ? Context->vcount - 1 : 0);
249 /* This should be in mx.c, but it only gets used here. */
250 static int mx_toggle_write (CONTEXT * ctx)
256 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
261 if (ctx->dontwrite) {
263 mutt_message (_("Changes to folder will be written on folder exit."));
267 mutt_message (_("Changes to folder will not be written."));
273 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
274 int oldcount, int index_hint)
276 /* store pointers to the newly added messages */
277 HEADER **save_new = NULL;
280 /* take note of the current message */
282 if (menu->current < Context->vcount)
283 menu->oldcurrent = index_hint;
285 oldcount = 0; /* invalid message number! */
288 /* We are in a limited view. Check if the new message(s) satisfy
289 * the limit criteria. If they do, set their virtual msgno so that
290 * they will be visible in the limited view */
291 if (Context->pattern) {
292 #define THIS_BODY Context->hdrs[j]->content
293 if (oldcount || check == M_REOPENED) {
294 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount;
296 if (mutt_pattern_exec
297 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
299 Context->hdrs[j]->virtual = Context->vcount;
300 Context->v2r[Context->vcount] = j;
301 Context->hdrs[j]->limited = 1;
304 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
311 /* save the list of new messages */
312 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
314 (HEADER **) safe_malloc (sizeof (HEADER *) *
315 (Context->msgcount - oldcount));
316 for (j = oldcount; j < Context->msgcount; j++)
317 save_new[j - oldcount] = Context->hdrs[j];
320 /* if the mailbox was reopened, need to rethread from scratch */
321 mutt_sort_headers (Context, (check == M_REOPENED));
323 /* uncollapse threads with new mail */
324 if ((Sort & SORT_MASK) == SORT_THREADS) {
325 if (check == M_REOPENED) {
328 Context->collapsed = 0;
330 for (h = Context->tree; h; h = h->next) {
331 for (j = h; !j->message; j = j->child);
332 mutt_uncollapse_thread (Context, j->message);
334 mutt_set_virtual (Context);
337 for (j = 0; j < Context->msgcount - oldcount; j++) {
340 for (k = 0; k < Context->msgcount; k++) {
341 HEADER *h = Context->hdrs[k];
343 if (h == save_new[j] && (!Context->pattern || h->limited))
344 mutt_uncollapse_thread (Context, h);
348 mutt_set_virtual (Context);
354 /* restore the current message to the message it was pointing to */
355 for (j = 0; j < Context->vcount; j++) {
356 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
363 if (menu->current < 0)
364 menu->current = ci_first_message ();
368 static void resort_index (MUTTMENU * menu)
371 HEADER *current = CURHDR;
374 mutt_sort_headers (Context, 0);
375 /* Restore the current message */
377 for (i = 0; i < Context->vcount; i++) {
378 if (Context->hdrs[Context->v2r[i]] == current) {
384 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
385 menu->current = mutt_parent_message (Context, current);
387 if (menu->current < 0)
388 menu->current = ci_first_message ();
390 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
393 struct mapping_t IndexHelp[] = {
394 {N_("Quit"), OP_QUIT},
395 {N_("Del"), OP_DELETE},
396 {N_("Undel"), OP_UNDELETE},
397 {N_("Save"), OP_SAVE},
398 {N_("Mail"), OP_MAIL},
399 {N_("Reply"), OP_REPLY},
400 {N_("Group"), OP_GROUP_REPLY},
401 {N_("Help"), OP_HELP},
406 struct mapping_t IndexNewsHelp[] = {
407 {N_("Quit"), OP_QUIT},
408 {N_("Del"), OP_DELETE},
409 {N_("Undel"), OP_UNDELETE},
410 {N_("Save"), OP_SAVE},
411 {N_("Post"), OP_POST},
412 {N_("Followup"), OP_FOLLOWUP},
413 {N_("Catchup"), OP_CATCHUP},
414 {N_("Help"), OP_HELP},
419 /* This function handles the message index window as well as commands returned
420 * from the pager (MENU_PAGER).
422 int mutt_index_menu (void)
424 char buf[LONG_STRING], helpstr[SHORT_STRING];
427 int done = 0; /* controls when to exit the "event" loop */
429 int tag = 0; /* has the tag-prefix command been pressed? */
434 char *cp; /* temporary variable. */
435 int index_hint; /* used to restore cursor position */
436 int do_buffy_notify = 1;
437 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
438 int attach_msg = option (OPTATTACHMSG);
440 menu = mutt_new_menu ();
441 menu->menu = MENU_MAIN;
443 menu->pagelen = LINES - 3;
444 menu->make_entry = index_make_entry;
445 menu->color = index_color;
446 menu->current = ci_first_message ();
447 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
450 && (Context->magic ==
451 M_NNTP)) ? IndexNewsHelp :
456 mutt_buffy_check (1); /* force the buffy check after we enter the folder */
457 /* record folder we open to place sidebar indicator properly */
458 if (Context && Context->path)
459 set_curbuffy (Context->path);
463 tag = 0; /* clear the tag-prefix */
465 menu->max = Context ? Context->vcount : 0;
466 oldcount = Context ? Context->msgcount : 0;
468 /* check if we need to resort the index because just about
469 * any 'op' below could do mutt_enter_command(), either here or
470 * from any new menu launched, and change $sort/$sort_aux
472 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
475 if (option (OPTREDRAWTREE) && Context && Context->msgcount
476 && (Sort & SORT_MASK) == SORT_THREADS) {
477 mutt_draw_tree (Context);
478 menu->redraw |= REDRAW_STATUS;
479 unset_option (OPTREDRAWTREE);
482 if (Context && !attach_msg) {
485 /* check for new mail in the mailbox. If nonzero, then something has
486 * changed about the file (either we got new mail or the file was
487 * modified underneath us.)
491 imap_allow_reopen (Context);
494 index_hint = (Context->vcount && menu->current >= 0
495 && menu->current < Context->vcount) ? CURHDR->index : 0;
497 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
498 if (!Context->path) {
499 /* fatal error occurred */
501 menu->redraw = REDRAW_FULL;
503 set_option (OPTSEARCHINVALID);
505 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
506 update_index (menu, Context, check, oldcount, index_hint);
508 /* notify the user of new mail */
509 if (check == M_REOPENED)
511 ("Mailbox was externally modified. Flags may be wrong."));
512 else if (check == M_NEW_MAIL) {
513 /* on new mail: redraw sidebar */
514 draw_sidebar (CurrentMenu);
515 mutt_message (_("New mail in this mailbox."));
517 if (option (OPTBEEPNEW))
520 else if (check == M_FLAGS)
521 mutt_message (_("Mailbox was externally modified."));
523 /* avoid the message being overwritten by buffy */
526 menu->redraw = REDRAW_FULL;
527 menu->max = Context->vcount;
529 set_option (OPTSEARCHINVALID);
535 imap_disallow_reopen (Context);
539 /* check for new mail in the incoming folders */
541 if ((newcount = mutt_buffy_check (0)) != oldcount) {
542 menu->redraw |= REDRAW_STATUS;
543 menu->redraw |= REDRAW_SIDEBAR;
545 if (do_buffy_notify) {
546 if (mutt_buffy_notify () && option (OPTBEEPNEW))
555 if (menu->redraw & REDRAW_SIDEBAR)
556 draw_sidebar (menu->menu);
557 if (menu->redraw & REDRAW_FULL) {
558 menu_redraw_full (menu);
559 draw_sidebar (menu->menu);
563 if (menu->menu == MENU_MAIN) {
564 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
565 menu_check_recenter (menu);
567 if (menu->redraw & REDRAW_INDEX) {
568 menu_redraw_index (menu);
569 menu->redraw |= REDRAW_STATUS;
571 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
572 menu_redraw_motion (menu);
573 else if (menu->redraw & REDRAW_CURRENT)
574 menu_redraw_current (menu);
577 if (menu->redraw & REDRAW_STATUS) {
579 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
581 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
582 SETCOLOR (MT_COLOR_STATUS);
583 mutt_paddstr (COLS, buf);
584 SETCOLOR (MT_COLOR_NORMAL);
585 set_buffystats (Context);
586 menu->redraw &= ~REDRAW_STATUS;
587 if (option (OPTXTERMSETTITLES)) {
588 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
589 set_xterm_title_bar (buf);
590 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
591 set_xterm_icon_name (buf);
596 if (menu->current < menu->max)
597 menu->oldcurrent = menu->current;
599 menu->oldcurrent = -1;
601 if (option (OPTARROWCURSOR))
602 move (menu->current - menu->top + menu->offset, 2);
604 move (menu->current - menu->top + menu->offset, COLS - 1);
607 op = km_dokey (MENU_MAIN);
610 (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op));
612 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
615 mutt_resize_screen ();
616 menu->redraw = REDRAW_FULL;
617 menu->menu = MENU_MAIN;
619 menu->top = 0; /* so we scroll the right amount */
621 * force a real complete redraw. clrtobot() doesn't seem to be able
622 * to handle every case without this.
624 clearok (stdscr, TRUE);
630 continue; /* either user abort or timeout */
634 /* special handling for the tag-prefix function */
635 if (op == OP_TAG_PREFIX) {
637 mutt_error (_("No mailbox is open."));
642 if (!Context->tagged) {
643 mutt_error (_("No tagged messages."));
649 /* give visual indication that the next command is a tag- command */
650 mvaddstr (LINES - 1, 0, "tag-");
653 /* get the real command */
654 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
655 /* abort tag sequence */
656 CLEARLINE (LINES - 1);
660 else if (option (OPTAUTOTAG) && Context && Context->tagged)
663 if (op == OP_TAG_PREFIX_COND) {
665 mutt_error (_("No mailbox is open."));
670 if (!Context->tagged) {
673 while (UngetCount > 0) {
675 if (tmp.op == OP_END_COND)
678 mutt_message (_("Nothing to do."));
684 /* give visual indication that the next command is a tag- command */
685 mvaddstr (LINES - 1, 0, "tag-");
688 /* get the real command */
689 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
690 /* abort tag sequence */
691 CLEARLINE (LINES - 1);
699 if (menu->current < menu->max)
700 menu->oldcurrent = menu->current;
702 menu->oldcurrent = -1;
704 mutt_curs_set (1); /* fallback from the pager */
708 unset_option (OPTNEWS); /* for any case */
713 /* ----------------------------------------------------------------------
718 menu_bottom_page (menu);
721 menu_first_entry (menu);
724 menu_middle_page (menu);
730 menu_half_down (menu);
733 menu_next_line (menu);
736 menu_prev_line (menu);
739 menu_next_page (menu);
742 menu_prev_page (menu);
745 menu_last_entry (menu);
748 menu_top_page (menu);
751 menu_current_top (menu);
753 case OP_CURRENT_MIDDLE:
754 menu_current_middle (menu);
756 case OP_CURRENT_BOTTOM:
757 menu_current_bottom (menu);
764 if (Context->magic == M_NNTP) {
767 if (op == OP_GET_MESSAGE) {
769 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0)
774 LIST *ref = CURHDR->env->references;
777 mutt_error (_("Article has no parent reference!"));
781 strfcpy (buf, ref->data, sizeof (buf));
783 if (!Context->id_hash)
784 Context->id_hash = mutt_make_id_hash (Context);
785 if ((h = hash_find (Context->id_hash, buf))) {
786 if (h->virtual != -1) {
787 menu->current = h->virtual;
788 menu->redraw = REDRAW_MOTION_RESYNCH;
790 else if (h->collapsed) {
791 mutt_uncollapse_thread (Context, h);
792 mutt_set_virtual (Context);
793 menu->current = h->virtual;
794 menu->redraw = REDRAW_MOTION_RESYNCH;
797 mutt_error (_("Message not visible in limited view."));
800 if (nntp_check_msgid (Context, buf) == 0) {
801 h = Context->hdrs[Context->msgcount - 1];
802 mutt_sort_headers (Context, 0);
803 menu->current = h->virtual;
804 menu->redraw = REDRAW_FULL;
807 mutt_error (_("Article %s not found on server"), buf);
812 case OP_GET_CHILDREN:
813 case OP_RECONSTRUCT_THREAD:
815 if (Context->magic == M_NNTP) {
817 int old = CURHDR->index, i;
819 if (!CURHDR->env->message_id) {
820 mutt_error (_("No Message-Id. Unable to perform operation"));
825 if (!Context->id_hash)
826 Context->id_hash = mutt_make_id_hash (Context);
827 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
829 if (op == OP_RECONSTRUCT_THREAD) {
830 LIST *ref = CURHDR->env->references;
833 nntp_check_msgid (Context, ref->data);
834 /* the last msgid in References is the root message */
836 strfcpy (buf, ref->data, sizeof (buf));
840 mutt_message (_("Check for children of message..."));
842 if (nntp_check_children (Context, buf) == 0) {
843 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
844 h = hash_find (Context->id_hash, buf);
845 /* if the root message was retrieved, move to it */
847 menu->current = h->virtual;
848 else /* try to restore old position */
849 for (i = 0; i < Context->msgcount; i++)
850 if (Context->hdrs[i]->index == old) {
851 menu->current = Context->hdrs[i]->virtual;
852 /* As an added courtesy, recenter the menu
853 * with the current entry at the middle of the screen */
854 menu_check_recenter (menu);
855 menu_current_middle (menu);
858 menu->redraw = REDRAW_FULL;
868 if (isdigit (LastKey))
869 mutt_ungetch (LastKey, 0);
871 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
875 if (!isdigit ((unsigned char) buf[0])) {
876 mutt_error (_("Argument must be a message number."));
882 if (i > 0 && i <= Context->msgcount) {
883 for (j = i - 1; j < Context->msgcount; j++) {
884 if (Context->hdrs[j]->virtual != -1)
887 if (j >= Context->msgcount) {
888 for (j = i - 2; j >= 0; j--) {
889 if (Context->hdrs[j]->virtual != -1)
895 menu->current = Context->hdrs[j]->virtual;
896 if (menu->menu == MENU_PAGER) {
897 op = OP_DISPLAY_MESSAGE;
901 menu->redraw = REDRAW_MOTION;
904 mutt_error (_("That message is not visible."));
907 mutt_error (_("Invalid message number."));
911 /* --------------------------------------------------------------------
912 * `index' specific commands
915 case OP_MAIN_DELETE_PATTERN:
922 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
926 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
927 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
931 case OP_MAIN_FETCH_MAIL:
935 menu->redraw = REDRAW_FULL;
941 mutt_help (MENU_MAIN);
942 menu->redraw = REDRAW_FULL;
945 case OP_MAIN_SHOW_LIMIT:
947 if (!Context->pattern)
948 mutt_message (_("No limit pattern is in effect."));
953 /* i18n: ask for a limit to apply */
954 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
955 mutt_message ("%s", buf);
963 menu->oldcurrent = (Context->vcount && menu->current >= 0
965 Context->vcount) ? CURHDR->index : -1;
966 if (op == OP_TOGGLE_READ) {
967 char buf[LONG_STRING];
969 if (!Context->pattern
970 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
971 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
972 Context->pattern ? Context->pattern : ".*");
973 set_option (OPTHIDEREAD);
976 strfcpy (buf, Context->pattern + 8, sizeof (buf));
977 if (!*buf || strncmp (buf, ".*", 2) == 0)
978 snprintf (buf, sizeof (buf), "~A");
979 unset_option (OPTHIDEREAD);
981 FREE (&Context->pattern);
982 Context->pattern = safe_strdup (buf);
984 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
985 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
987 if (menu->oldcurrent >= 0) {
988 /* try to find what used to be the current message */
990 for (i = 0; i < Context->vcount; i++)
991 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
995 if (menu->current < 0)
1000 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1001 if ((Sort & SORT_MASK) == SORT_THREADS)
1002 mutt_draw_tree (Context);
1003 menu->redraw = REDRAW_FULL;
1015 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1018 oldcount = Context ? Context->msgcount : 0;
1021 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1024 if (check == M_NEW_MAIL || check == M_REOPENED)
1025 update_index (menu, Context, check, oldcount, index_hint);
1027 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1028 set_option (OPTSEARCHINVALID);
1035 clearok (stdscr, TRUE);
1036 menu->redraw = REDRAW_FULL;
1040 case OP_SEARCH_REVERSE:
1041 case OP_SEARCH_NEXT:
1042 case OP_SEARCH_OPPOSITE:
1046 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1047 menu->current = menu->oldcurrent;
1049 menu->redraw = REDRAW_MOTION;
1053 case OP_SORT_REVERSE:
1055 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1056 if (Context && Context->msgcount) {
1057 resort_index (menu);
1058 set_option (OPTSEARCHINVALID);
1067 if (tag && !option (OPTAUTOTAG)) {
1068 for (j = 0; j < Context->vcount; j++)
1069 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1070 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1073 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1074 Context->last_tag = CURHDR->tagged ? CURHDR :
1075 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1076 ? NULL : Context->last_tag);
1077 menu->redraw = REDRAW_STATUS;
1078 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1080 menu->redraw |= REDRAW_MOTION_RESYNCH;
1083 menu->redraw |= REDRAW_CURRENT;
1087 case OP_MAIN_TAG_PATTERN:
1091 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1092 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1095 case OP_MAIN_UNDELETE_PATTERN:
1102 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1105 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1107 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1110 case OP_MAIN_UNTAG_PATTERN:
1114 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1115 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1118 /* --------------------------------------------------------------------
1119 * The following operations can be performed inside of the pager.
1123 case OP_MAIN_IMAP_FETCH:
1124 if (Context->magic == M_IMAP)
1125 imap_check_mailbox (Context, &index_hint, 1);
1129 case OP_MAIN_SYNC_FOLDER:
1131 if (Context && !Context->msgcount)
1138 int oldvcount = Context->vcount;
1139 int oldcount = Context->msgcount;
1143 /* calculate the number of messages _above_ the cursor,
1144 * so we can keep the cursor on the current message
1146 for (j = 0; j <= menu->current; j++) {
1147 if (Context->hdrs[Context->v2r[j]]->deleted)
1151 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1152 if (Context->vcount != oldvcount)
1153 menu->current -= dcount;
1154 set_option (OPTSEARCHINVALID);
1156 else if (check == M_NEW_MAIL || check == M_REOPENED)
1157 update_index (menu, Context, check, oldcount, index_hint);
1160 * do a sanity check even if mx_sync_mailbox failed.
1163 if (menu->current < 0 || menu->current >= Context->vcount)
1164 menu->current = ci_first_message ();
1167 /* check for a fatal error, or all messages deleted */
1171 /* if we were in the pager, redisplay the message */
1172 if (menu->menu == MENU_PAGER) {
1173 op = OP_DISPLAY_MESSAGE;
1177 menu->redraw = REDRAW_FULL;
1180 case OP_SIDEBAR_OPEN:
1181 case OP_MAIN_CHANGE_FOLDER:
1182 case OP_MAIN_CHANGE_FOLDER_READONLY:
1184 case OP_MAIN_CHANGE_GROUP:
1185 case OP_MAIN_CHANGE_GROUP_READONLY:
1187 if (attach_msg || option (OPTREADONLY) ||
1189 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1191 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1197 cp = _("Open mailbox in read-only mode");
1199 cp = _("Open mailbox");
1203 unset_option (OPTNEWS);
1204 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1205 set_option (OPTNEWS);
1206 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1209 cp = _("Open newsgroup in read-only mode");
1211 cp = _("Open newsgroup");
1217 if (Context && Context->path)
1218 strncpy (buf, Context->path, sizeof (buf));
1219 mutt_buffy (buf, sizeof (buf));
1222 if (op == OP_SIDEBAR_OPEN) {
1225 strncpy (buf, CurBuffy->path, sizeof (buf));
1227 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1231 CLEARLINE (LINES - 1);
1236 if (option (OPTNEWS)) {
1237 unset_option (OPTNEWS);
1238 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1242 mutt_expand_path (buf, sizeof (buf));
1244 if (mx_get_magic (buf) <= 0) {
1245 mutt_error (_("%s is not a mailbox."), buf);
1248 mutt_str_replace (&CurrentFolder, buf);
1253 #ifdef USE_COMPRESSED
1254 if (Context->compressinfo && Context->realpath)
1255 mutt_str_replace (&LastFolder, Context->realpath);
1259 mutt_str_replace (&LastFolder, Context->path);
1260 oldcount = Context ? Context->msgcount : 0;
1262 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1263 if (check == M_NEW_MAIL || check == M_REOPENED)
1264 update_index (menu, Context, check, oldcount, index_hint);
1266 set_option (OPTSEARCHINVALID);
1267 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1275 /* Set CurrentMenu to MENU_MAIN before executing any folder
1276 * hooks so that all the index menu functions are available to
1280 CurrentMenu = MENU_MAIN;
1281 mutt_folder_hook (buf);
1283 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1284 menu->current = ci_first_message ();
1290 /* mutt_buffy_check() must be done with mail-reader mode! */
1291 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1293 && (Context->magic ==
1294 M_NNTP)) ? IndexNewsHelp :
1297 mutt_clear_error ();
1298 mutt_buffy_check (1); /* force the buffy check after we have changed
1300 menu->redraw = REDRAW_FULL;
1301 set_option (OPTSEARCHINVALID);
1304 case OP_DISPLAY_MESSAGE:
1305 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1310 * toggle the weeding of headers so that a user can press the key
1311 * again while reading the message.
1313 if (op == OP_DISPLAY_HEADERS)
1314 toggle_option (OPTWEED);
1316 unset_option (OPTNEEDRESORT);
1318 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1319 mutt_uncollapse_thread (Context, CURHDR);
1320 mutt_set_virtual (Context);
1321 if (option (OPTUNCOLLAPSEJUMP))
1322 menu->current = mutt_thread_next_unread (Context, CURHDR);
1325 if ((op = mutt_display_message (CURHDR)) == -1) {
1326 unset_option (OPTNEEDRESORT);
1330 menu->menu = MENU_PAGER;
1331 menu->oldcurrent = menu->current;
1337 if (menu->menu == MENU_MAIN && attach_msg) {
1342 if ((menu->menu == MENU_MAIN)
1343 && (query_quadoption (OPT_QUIT,
1344 _("Exit Mutt-ng without saving?")) == M_YES))
1347 mx_fastclose_mailbox (Context);
1359 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1360 /* if we were in the pager, redisplay the message */
1361 if (menu->menu == MENU_PAGER) {
1362 op = OP_DISPLAY_MESSAGE;
1366 menu->redraw = REDRAW_CURRENT;
1369 case OP_MAIN_BREAK_THREAD:
1375 if ((Sort & SORT_MASK) != SORT_THREADS)
1376 mutt_error (_("Threading is not enabled."));
1380 HEADER *oldcur = CURHDR;
1382 mutt_break_thread (CURHDR);
1383 mutt_sort_headers (Context, 1);
1384 menu->current = oldcur->virtual;
1387 Context->changed = 1;
1388 mutt_message _("Thread broken");
1390 if (menu->menu == MENU_PAGER) {
1391 op = OP_DISPLAY_MESSAGE;
1395 menu->redraw |= REDRAW_INDEX;
1399 case OP_MAIN_LINK_THREADS:
1405 if ((Sort & SORT_MASK) != SORT_THREADS)
1406 mutt_error (_("Threading is not enabled."));
1408 else if (!CURHDR->env->message_id)
1409 mutt_error (_("No Message-ID: header available to link thread"));
1411 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1412 mutt_error (_("First, please tag a message to be linked here"));
1415 HEADER *oldcur = CURHDR;
1417 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1419 mutt_sort_headers (Context, 1);
1420 menu->current = oldcur->virtual;
1422 Context->changed = 1;
1423 mutt_message _("Threads linked");
1426 mutt_error (_("No thread linked"));
1429 if (menu->menu == MENU_PAGER) {
1430 op = OP_DISPLAY_MESSAGE;
1434 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1437 case OP_MAIN_NEXT_UNDELETED:
1441 if (menu->current >= Context->vcount - 1) {
1442 if (menu->menu == MENU_MAIN)
1443 mutt_error (_("You are on the last message."));
1447 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1448 menu->current = menu->oldcurrent;
1449 if (menu->menu == MENU_MAIN)
1450 mutt_error (_("No undeleted messages."));
1452 else if (menu->menu == MENU_PAGER) {
1453 op = OP_DISPLAY_MESSAGE;
1457 menu->redraw = REDRAW_MOTION;
1464 if (menu->current >= Context->vcount - 1) {
1465 if (menu->menu == MENU_MAIN)
1466 mutt_error (_("You are on the last message."));
1471 if (menu->menu == MENU_PAGER) {
1472 op = OP_DISPLAY_MESSAGE;
1476 menu->redraw = REDRAW_MOTION;
1479 case OP_MAIN_PREV_UNDELETED:
1483 if (menu->current < 1) {
1484 mutt_error (_("You are on the first message."));
1488 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1489 menu->current = menu->oldcurrent;
1490 if (menu->menu == MENU_MAIN)
1491 mutt_error (_("No undeleted messages."));
1493 else if (menu->menu == MENU_PAGER) {
1494 op = OP_DISPLAY_MESSAGE;
1498 menu->redraw = REDRAW_MOTION;
1505 if (menu->current < 1) {
1506 if (menu->menu == MENU_MAIN)
1507 mutt_error (_("You are on the first message."));
1512 if (menu->menu == MENU_PAGER) {
1513 op = OP_DISPLAY_MESSAGE;
1517 menu->redraw = REDRAW_MOTION;
1520 case OP_DECRYPT_COPY:
1521 case OP_DECRYPT_SAVE:
1525 case OP_COPY_MESSAGE:
1527 case OP_DECODE_COPY:
1528 case OP_DECODE_SAVE:
1531 if (mutt_save_message (tag ? NULL : CURHDR,
1532 (op == OP_DECRYPT_SAVE) ||
1533 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1534 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1535 (op == OP_DECRYPT_SAVE)
1536 || (op == OP_DECRYPT_COPY)
1537 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1544 menu->redraw |= REDRAW_INDEX;
1545 else if (option (OPTRESOLVE)) {
1546 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1547 menu->current = menu->oldcurrent;
1548 menu->redraw |= REDRAW_CURRENT;
1551 menu->redraw |= REDRAW_MOTION_RESYNCH;
1554 menu->redraw |= REDRAW_CURRENT;
1558 case OP_MAIN_NEXT_NEW:
1559 case OP_MAIN_NEXT_UNREAD:
1560 case OP_MAIN_PREV_NEW:
1561 case OP_MAIN_PREV_UNREAD:
1562 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1563 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1566 int first_unread = -1;
1574 for (j = 0; j != Context->vcount; j++) {
1575 #define CURHDRi Context->hdrs[Context->v2r[i]]
1576 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1577 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1579 if (i > Context->vcount - 1) {
1580 mutt_message _("Search wrapped to top.");
1588 mutt_message _("Search wrapped to bottom.");
1590 i = Context->vcount - 1;
1594 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1595 if (UNREAD (CURHDRi) && first_unread == -1)
1597 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1600 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1601 if (first_unread == -1)
1603 if ((!CURHDRi->old) && first_new == -1)
1607 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1610 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1611 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1612 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1617 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1618 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1619 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1621 menu->current = first_new;
1622 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1623 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1624 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1625 && first_unread != -1)
1626 menu->current = first_unread;
1628 if (menu->current == -1) {
1629 menu->current = menu->oldcurrent;
1630 mutt_error ("%s%s.",
1631 (op == OP_MAIN_NEXT_NEW
1633 OP_MAIN_PREV_NEW) ? _("No new messages") :
1634 _("No unread messages"),
1635 Context->pattern ? _(" in this limited view") : "");
1637 else if (menu->menu == MENU_PAGER) {
1638 op = OP_DISPLAY_MESSAGE;
1642 menu->redraw = REDRAW_MOTION;
1645 case OP_FLAG_MESSAGE:
1652 if (Context->magic == M_POP) {
1654 mutt_error (_("Can't change 'important' flag on POP server."));
1661 CHECK_IMAP_ACL (IMAP_ACL_WRITE);
1665 if (Context->magic == M_NNTP) {
1667 mutt_error (_("Can't change 'important' flag on NNTP server."));
1674 for (j = 0; j < Context->vcount; j++) {
1675 if (Context->hdrs[Context->v2r[j]]->tagged)
1676 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1677 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1680 menu->redraw |= REDRAW_INDEX;
1683 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1684 if (option (OPTRESOLVE)) {
1685 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1686 menu->current = menu->oldcurrent;
1687 menu->redraw = REDRAW_CURRENT;
1690 menu->redraw = REDRAW_MOTION_RESYNCH;
1693 menu->redraw = REDRAW_CURRENT;
1695 menu->redraw |= REDRAW_STATUS;
1705 CHECK_IMAP_ACL (IMAP_ACL_SEEN);
1709 for (j = 0; j < Context->vcount; j++) {
1710 if (Context->hdrs[Context->v2r[j]]->tagged) {
1711 if (Context->hdrs[Context->v2r[j]]->read ||
1712 Context->hdrs[Context->v2r[j]]->old)
1713 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1716 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1720 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1723 if (CURHDR->read || CURHDR->old)
1724 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1726 mutt_set_flag (Context, CURHDR, M_READ, 1);
1728 if (option (OPTRESOLVE)) {
1729 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1730 menu->current = menu->oldcurrent;
1731 menu->redraw = REDRAW_CURRENT;
1734 menu->redraw = REDRAW_MOTION_RESYNCH;
1737 menu->redraw = REDRAW_CURRENT;
1738 menu->redraw |= REDRAW_STATUS;
1742 case OP_TOGGLE_WRITE:
1745 if (mx_toggle_write (Context) == 0)
1746 menu->redraw |= REDRAW_STATUS;
1749 case OP_MAIN_NEXT_THREAD:
1750 case OP_MAIN_NEXT_SUBTHREAD:
1751 case OP_MAIN_PREV_THREAD:
1752 case OP_MAIN_PREV_SUBTHREAD:
1757 case OP_MAIN_NEXT_THREAD:
1758 menu->current = mutt_next_thread (CURHDR);
1761 case OP_MAIN_NEXT_SUBTHREAD:
1762 menu->current = mutt_next_subthread (CURHDR);
1765 case OP_MAIN_PREV_THREAD:
1766 menu->current = mutt_previous_thread (CURHDR);
1769 case OP_MAIN_PREV_SUBTHREAD:
1770 menu->current = mutt_previous_subthread (CURHDR);
1774 if (menu->current < 0) {
1775 menu->current = menu->oldcurrent;
1776 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1777 mutt_error (_("No more threads."));
1780 mutt_error (_("You are on the first thread."));
1782 else if (menu->menu == MENU_PAGER) {
1783 op = OP_DISPLAY_MESSAGE;
1787 menu->redraw = REDRAW_MOTION;
1790 case OP_MAIN_PARENT_MESSAGE:
1795 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1796 menu->current = menu->oldcurrent;
1798 else if (menu->menu == MENU_PAGER) {
1799 op = OP_DISPLAY_MESSAGE;
1803 menu->redraw = REDRAW_MOTION;
1806 case OP_MAIN_SET_FLAG:
1807 case OP_MAIN_CLEAR_FLAG:
1814 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1817 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1819 menu->redraw = REDRAW_STATUS;
1821 menu->redraw |= REDRAW_INDEX;
1822 else if (option (OPTRESOLVE)) {
1823 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1824 menu->current = menu->oldcurrent;
1825 menu->redraw |= REDRAW_CURRENT;
1828 menu->redraw |= REDRAW_MOTION_RESYNCH;
1831 menu->redraw |= REDRAW_CURRENT;
1835 case OP_MAIN_COLLAPSE_THREAD:
1839 if ((Sort & SORT_MASK) != SORT_THREADS) {
1840 mutt_error (_("Threading is not enabled."));
1845 if (CURHDR->collapsed) {
1846 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1847 mutt_set_virtual (Context);
1848 if (option (OPTUNCOLLAPSEJUMP))
1849 menu->current = mutt_thread_next_unread (Context, CURHDR);
1851 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1852 menu->current = mutt_collapse_thread (Context, CURHDR);
1853 mutt_set_virtual (Context);
1856 mutt_error (_("Thread contains unread messages."));
1861 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1865 case OP_MAIN_COLLAPSE_ALL:
1869 if ((Sort & SORT_MASK) != SORT_THREADS) {
1870 mutt_error (_("Threading is not enabled."));
1877 THREAD *thread, *top;
1880 if (CURHDR->collapsed)
1881 final = mutt_uncollapse_thread (Context, CURHDR);
1882 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1883 final = mutt_collapse_thread (Context, CURHDR);
1885 final = CURHDR->virtual;
1887 base = Context->hdrs[Context->v2r[final]];
1889 top = Context->tree;
1890 Context->collapsed = !Context->collapsed;
1891 while ((thread = top) != NULL) {
1892 while (!thread->message)
1893 thread = thread->child;
1894 h = thread->message;
1896 if (h->collapsed != Context->collapsed) {
1898 mutt_uncollapse_thread (Context, h);
1899 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1900 mutt_collapse_thread (Context, h);
1905 mutt_set_virtual (Context);
1906 for (j = 0; j < Context->vcount; j++) {
1907 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1913 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1917 /* --------------------------------------------------------------------
1918 * These functions are invoked directly from the internal-pager
1921 case OP_BOUNCE_MESSAGE:
1926 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1929 case OP_CREATE_ALIAS:
1931 mutt_create_alias (Context
1932 && Context->vcount ? CURHDR->env : NULL, NULL);
1933 MAYBE_REDRAW (menu->redraw);
1934 menu->redraw |= REDRAW_CURRENT;
1939 mutt_query_menu (NULL, 0);
1940 MAYBE_REDRAW (menu->redraw);
1943 case OP_PURGE_MESSAGE:
1951 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1955 mutt_tag_set_flag (M_DELETE, 1);
1956 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1957 if (option (OPTDELETEUNTAG))
1958 mutt_tag_set_flag (M_TAG, 0);
1959 menu->redraw = REDRAW_INDEX;
1962 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1963 mutt_set_flag (Context, CURHDR, M_PURGED,
1964 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1965 if (option (OPTDELETEUNTAG))
1966 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1967 if (option (OPTRESOLVE)) {
1968 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1969 menu->current = menu->oldcurrent;
1970 menu->redraw = REDRAW_CURRENT;
1972 else if (menu->menu == MENU_PAGER) {
1973 op = OP_DISPLAY_MESSAGE;
1977 menu->redraw |= REDRAW_MOTION_RESYNCH;
1980 menu->redraw = REDRAW_CURRENT;
1982 menu->redraw |= REDRAW_STATUS;
1985 case OP_DELETE_THREAD:
1986 case OP_DELETE_SUBTHREAD:
1993 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1996 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1997 op == OP_DELETE_THREAD ? 0 : 1);
2000 if (option (OPTDELETEUNTAG))
2001 mutt_thread_set_flag (CURHDR, M_TAG, 0,
2002 op == OP_DELETE_THREAD ? 0 : 1);
2003 if (option (OPTRESOLVE))
2004 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
2005 menu->current = menu->oldcurrent;
2006 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2012 if (Context && Context->magic == M_NNTP) {
2013 if (mutt_newsgroup_catchup (CurrentNewsSrv,
2014 ((NNTP_DATA *) Context->data)->group))
2015 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2020 case OP_DISPLAY_ADDRESS:
2024 mutt_display_address (CURHDR->env);
2027 case OP_ENTER_COMMAND:
2029 CurrentMenu = MENU_MAIN;
2030 mutt_enter_command ();
2031 mutt_check_rescore (Context);
2032 if (option (OPTFORCEREDRAWINDEX))
2033 menu->redraw = REDRAW_FULL;
2034 unset_option (OPTFORCEREDRAWINDEX);
2035 unset_option (OPTFORCEREDRAWPAGER);
2038 case OP_EDIT_MESSAGE:
2046 if (Context->magic == M_POP) {
2048 mutt_error (_("Can't edit message on POP server."));
2055 CHECK_IMAP_ACL (IMAP_ACL_INSERT);
2059 if (Context->magic == M_NNTP) {
2061 mutt_error (_("Can't edit message on newsserver."));
2067 if (option (OPTPGPAUTODEC)
2068 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2069 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2070 mutt_edit_message (Context, tag ? NULL : CURHDR);
2071 menu->redraw = REDRAW_FULL;
2075 case OP_FORWARD_MESSAGE:
2080 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2081 menu->redraw = REDRAW_FULL;
2085 case OP_FORGET_PASSPHRASE:
2086 crypt_forget_passphrase ();
2089 case OP_GROUP_REPLY:
2094 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2095 tag ? NULL : CURHDR);
2096 menu->redraw = REDRAW_FULL;
2104 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2105 tag ? NULL : CURHDR);
2106 menu->redraw = REDRAW_FULL;
2112 ci_send_message (0, NULL, NULL, Context, NULL);
2113 menu->redraw = REDRAW_FULL;
2117 if (!(WithCrypto & APPLICATION_PGP))
2120 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2121 menu->redraw = REDRAW_FULL;
2125 case OP_EXTRACT_KEYS:
2130 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2131 menu->redraw = REDRAW_FULL;
2135 case OP_CHECK_TRADITIONAL:
2136 if (!(WithCrypto & APPLICATION_PGP))
2140 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2141 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2143 if (menu->menu == MENU_PAGER) {
2144 op = OP_DISPLAY_MESSAGE;
2153 mutt_pipe_message (tag ? NULL : CURHDR);
2154 MAYBE_REDRAW (menu->redraw);
2161 mutt_print_message (tag ? NULL : CURHDR);
2164 case OP_MAIN_READ_THREAD:
2165 case OP_MAIN_READ_SUBTHREAD:
2172 CHECK_IMAP_ACL (IMAP_ACL_SEEN);
2175 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2176 op == OP_MAIN_READ_THREAD ? 0 : 1);
2179 if (option (OPTRESOLVE)) {
2180 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2181 mutt_next_thread (CURHDR) :
2182 mutt_next_subthread (CURHDR))) == -1)
2183 menu->current = menu->oldcurrent;
2185 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2189 case OP_RECALL_MESSAGE:
2192 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2193 menu->redraw = REDRAW_FULL;
2203 for (j = 0; j < Context->vcount; j++) {
2204 if (Context->hdrs[Context->v2r[j]]->tagged)
2205 mutt_resend_message (NULL, Context,
2206 Context->hdrs[Context->v2r[j]]);
2210 mutt_resend_message (NULL, Context, CURHDR);
2212 menu->redraw = REDRAW_FULL;
2218 case OP_FORWARD_TO_GROUP:
2221 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2222 Context && Context->msgcount == 0) {
2223 mutt_error (_("There are no messages."));
2226 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2227 mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2228 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2229 _("Reply by mail as poster prefers?")) !=
2231 if (Context && Context->magic == M_NNTP
2232 && !((NNTP_DATA *) Context->data)->allowed
2233 && query_quadoption (OPT_TOMODERATED,
2235 ("Posting to this group not allowed, may be moderated. Continue?"))
2239 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2242 if (op == OP_FOLLOWUP)
2243 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2244 tag ? NULL : CURHDR);
2246 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2247 tag ? NULL : CURHDR);
2249 menu->redraw = REDRAW_FULL;
2259 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2260 menu->redraw = REDRAW_FULL;
2263 case OP_SHELL_ESCAPE:
2265 mutt_shell_escape ();
2266 MAYBE_REDRAW (menu->redraw);
2270 case OP_TAG_SUBTHREAD:
2274 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2275 op == OP_TAG_THREAD ? 0 : 1);
2278 if (option (OPTRESOLVE)) {
2279 menu->current = mutt_next_thread (CURHDR);
2281 if (menu->current == -1)
2282 menu->current = menu->oldcurrent;
2284 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2295 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2299 mutt_tag_set_flag (M_DELETE, 0);
2300 mutt_tag_set_flag (M_PURGED, 0);
2301 menu->redraw = REDRAW_INDEX;
2304 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2305 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2306 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2308 menu->redraw = REDRAW_MOTION_RESYNCH;
2311 menu->redraw = REDRAW_CURRENT;
2313 menu->redraw |= REDRAW_STATUS;
2316 case OP_UNDELETE_THREAD:
2317 case OP_UNDELETE_SUBTHREAD:
2324 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2327 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2328 op == OP_UNDELETE_THREAD ? 0 : 1)
2329 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2330 op == OP_UNDELETE_THREAD ? 0 : 1);
2333 if (option (OPTRESOLVE)) {
2334 if (op == OP_UNDELETE_THREAD)
2335 menu->current = mutt_next_thread (CURHDR);
2337 menu->current = mutt_next_subthread (CURHDR);
2339 if (menu->current == -1)
2340 menu->current = menu->oldcurrent;
2342 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2352 menu->redraw = REDRAW_FULL;
2355 case OP_VIEW_ATTACHMENTS:
2358 mutt_view_attachments (CURHDR);
2359 if (CURHDR->attach_del)
2360 Context->changed = 1;
2361 menu->redraw = REDRAW_FULL;
2371 case OP_SIDEBAR_SCROLL_UP:
2372 case OP_SIDEBAR_SCROLL_DOWN:
2373 case OP_SIDEBAR_NEXT:
2374 case OP_SIDEBAR_PREV:
2375 case OP_SIDEBAR_NEXT_NEW:
2376 case OP_SIDEBAR_PREV_NEW:
2377 scroll_sidebar (op, menu->menu);
2380 if (menu->menu == MENU_MAIN)
2381 km_error_key (MENU_MAIN);
2384 if (menu->menu == MENU_PAGER) {
2385 menu->menu = MENU_MAIN;
2386 menu->redraw = REDRAW_FULL;
2388 set_option (OPTWEED); /* turn header weeding back on. */
2397 /* Close all open IMAP connections */
2402 /* Close all open NNTP connections */
2407 mutt_menuDestroy (&menu);
2411 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2418 for (color = ColorIndexList; color; color = color->next)
2419 if (mutt_pattern_exec
2420 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2421 curhdr->pair = color->pair;
2424 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];