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"
23 #include "recvattach.h"
35 #include "imap_private.h"
38 #include "mutt_crypt.h"
45 #include "mutt_sasl.h"
51 #include "lib/debug.h"
61 static const char *No_mailbox_is_open = N_("No mailbox is open.");
62 static const char *There_are_no_messages = N_("There are no messages.");
63 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
64 static const char *Function_not_permitted_in_attach_message_mode =
65 N_("Function not permitted in attach-message mode.");
66 static const char *No_visible = N_("No visible messages.");
68 #define CHECK_IN_MAILBOX if (!Context) \
71 mutt_error (_(No_mailbox_is_open)); \
75 #define CHECK_MSGCOUNT if (!Context) \
78 mutt_error(_(No_mailbox_is_open)); \
81 else if (!Context->msgcount) \
84 mutt_error(_(There_are_no_messages)); \
88 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
91 mutt_error(_(No_visible)); \
96 #define CHECK_READONLY if (Context->readonly) \
99 mutt_error(_(Mailbox_is_read_only)); \
103 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
106 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
110 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
111 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
112 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
113 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
115 extern const char *ReleaseDate;
116 extern size_t UngetCount;
118 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
121 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
122 int edgemsgno, reverse = Sort & SORT_REVERSE;
123 HEADER *h = Context->hdrs[Context->v2r[num]];
126 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
127 flag |= M_FORMAT_TREE; /* display the thread tree */
128 if (h->display_subject)
129 flag |= M_FORMAT_FORCESUBJ;
132 if (menu->top + menu->pagelen > menu->max)
133 edgemsgno = Context->v2r[menu->max - 1];
135 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
138 edgemsgno = Context->v2r[menu->top];
140 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
144 /* if no ancestor is visible on current screen, provisionally force
146 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
148 flag |= M_FORMAT_FORCESUBJ;
151 else if (tmp->message->virtual >= 0)
154 if (flag & M_FORMAT_FORCESUBJ) {
155 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
159 /* ...but if a previous sibling is available, don't force it */
160 if (reverse ? tmp->message->msgno >
161 edgemsgno : tmp->message->msgno < edgemsgno)
163 else if (tmp->message->virtual >= 0) {
164 flag &= ~M_FORMAT_FORCESUBJ;
172 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
175 int index_color (int index_no)
177 HEADER *h = Context->hdrs[Context->v2r[index_no]];
182 mutt_set_header_color (Context, h);
186 static int ci_next_undeleted (int msgno)
190 for (i = msgno + 1; i < Context->vcount; i++)
191 if (!Context->hdrs[Context->v2r[i]]->deleted)
196 static int ci_previous_undeleted (int msgno)
200 for (i = msgno - 1; i >= 0; i--)
201 if (!Context->hdrs[Context->v2r[i]]->deleted)
206 /* Return the index of the first new message, or failing that, the first
209 static int ci_first_message (void)
213 if (Context && Context->msgcount) {
214 for (i = 0; i < Context->vcount; i++) {
215 if (!Context->hdrs[Context->v2r[i]]->read &&
216 !Context->hdrs[Context->v2r[i]]->deleted) {
217 if (!Context->hdrs[Context->v2r[i]]->old)
226 /* If Sort is reverse and not threaded, the latest message is first.
227 * If Sort is threaded, the latest message is first iff exactly one
228 * of Sort and SortAux are reverse.
230 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
231 ((Sort & SORT_MASK) == SORT_THREADS &&
232 ((Sort ^ SortAux) & SORT_REVERSE)))
235 return (Context->vcount ? Context->vcount - 1 : 0);
240 /* This should be in mx.c, but it only gets used here. */
241 static int mx_toggle_write (CONTEXT * ctx)
247 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
252 if (ctx->dontwrite) {
254 mutt_message (_("Changes to folder will be written on folder exit."));
258 mutt_message (_("Changes to folder will not be written."));
264 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
265 int oldcount, int index_hint)
267 /* store pointers to the newly added messages */
268 HEADER **save_new = NULL;
271 /* take note of the current message */
273 if (menu->current < Context->vcount)
274 menu->oldcurrent = index_hint;
276 oldcount = 0; /* invalid message number! */
279 /* We are in a limited view. Check if the new message(s) satisfy
280 * the limit criteria. If they do, set their virtual msgno so that
281 * they will be visible in the limited view */
282 if (Context->pattern) {
283 #define THIS_BODY Context->hdrs[j]->content
284 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
285 if (mutt_pattern_exec
286 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
288 Context->hdrs[j]->virtual = Context->vcount;
289 Context->v2r[Context->vcount] = j;
290 Context->hdrs[j]->limited = 1;
293 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
299 /* save the list of new messages */
300 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
302 (HEADER **) mem_malloc (sizeof (HEADER *) *
303 (Context->msgcount - oldcount));
304 for (j = oldcount; j < Context->msgcount; j++)
305 save_new[j - oldcount] = Context->hdrs[j];
308 /* if the mailbox was reopened, need to rethread from scratch */
309 mutt_sort_headers (Context, (check == M_REOPENED));
311 /* uncollapse threads with new mail */
312 if ((Sort & SORT_MASK) == SORT_THREADS) {
313 if (check == M_REOPENED) {
316 Context->collapsed = 0;
318 for (h = Context->tree; h; h = h->next) {
319 for (j = h; !j->message; j = j->child);
320 mutt_uncollapse_thread (Context, j->message);
322 mutt_set_virtual (Context);
325 for (j = 0; j < Context->msgcount - oldcount; j++) {
328 for (k = 0; k < Context->msgcount; k++) {
329 HEADER *h = Context->hdrs[k];
331 if (h == save_new[j] && (!Context->pattern || h->limited))
332 mutt_uncollapse_thread (Context, h);
335 mem_free (&save_new);
336 mutt_set_virtual (Context);
342 /* restore the current message to the message it was pointing to */
343 for (j = 0; j < Context->vcount; j++) {
344 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
351 if (menu->current < 0)
352 menu->current = ci_first_message ();
355 static void resort_index (MUTTMENU * menu)
358 HEADER *current = CURHDR;
361 mutt_sort_headers (Context, 0);
362 /* Restore the current message */
364 for (i = 0; i < Context->vcount; i++) {
365 if (Context->hdrs[Context->v2r[i]] == current) {
371 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
372 menu->current = mutt_parent_message (Context, current);
374 if (menu->current < 0)
375 menu->current = ci_first_message ();
377 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
380 struct mapping_t IndexHelp[] = {
381 {N_("Quit"), OP_QUIT},
382 {N_("Del"), OP_DELETE},
383 {N_("Undel"), OP_UNDELETE},
384 {N_("Save"), OP_SAVE},
385 {N_("Mail"), OP_MAIL},
386 {N_("Reply"), OP_REPLY},
387 {N_("Group"), OP_GROUP_REPLY},
388 {N_("Help"), OP_HELP},
393 struct mapping_t IndexNewsHelp[] = {
394 {N_("Quit"), OP_QUIT},
395 {N_("Del"), OP_DELETE},
396 {N_("Undel"), OP_UNDELETE},
397 {N_("Save"), OP_SAVE},
398 {N_("Post"), OP_POST},
399 {N_("Followup"), OP_FOLLOWUP},
400 {N_("Catchup"), OP_CATCHUP},
401 {N_("Help"), OP_HELP},
406 /* This function handles the message index window as well as commands returned
407 * from the pager (MENU_PAGER).
409 int mutt_index_menu (void)
411 char buf[LONG_STRING], helpstr[SHORT_STRING];
414 int done = 0; /* controls when to exit the "event" loop */
416 int tag = 0; /* has the tag-prefix command been pressed? */
421 char *cp; /* temporary variable. */
422 int index_hint; /* used to restore cursor position */
423 int do_buffy_notify = 1;
424 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
425 int attach_msg = option (OPTATTACHMSG);
427 menu = mutt_new_menu ();
428 menu->menu = MENU_MAIN;
430 menu->pagelen = LINES - 3;
431 menu->make_entry = index_make_entry;
432 menu->color = index_color;
433 menu->current = ci_first_message ();
434 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
437 && (Context->magic ==
438 M_NNTP)) ? IndexNewsHelp :
443 buffy_check (1); /* force the buffy check after we enter the folder */
444 /* record folder we open to place sidebar indicator properly */
445 if (Context && Context->path)
446 sidebar_set_current (Context->path);
450 tag = 0; /* clear the tag-prefix */
452 menu->max = Context ? Context->vcount : 0;
453 oldcount = Context ? Context->msgcount : 0;
455 /* check if we need to resort the index because just about
456 * any 'op' below could do mutt_enter_command(), either here or
457 * from any new menu launched, and change $sort/$sort_aux
459 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
462 if (option (OPTREDRAWTREE) && Context && Context->msgcount
463 && (Sort & SORT_MASK) == SORT_THREADS) {
464 mutt_draw_tree (Context);
465 menu->redraw |= REDRAW_STATUS;
466 unset_option (OPTREDRAWTREE);
469 if (Context && !attach_msg) {
472 /* check for new mail in the mailbox. If nonzero, then something has
473 * changed about the file (either we got new mail or the file was
474 * modified underneath us.)
478 imap_allow_reopen (Context);
481 index_hint = (Context->vcount && menu->current >= 0
482 && menu->current < Context->vcount) ? CURHDR->index : 0;
484 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
485 if (!Context->path) {
486 /* fatal error occurred */
488 menu->redraw = REDRAW_FULL;
490 set_option (OPTSEARCHINVALID);
492 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
493 update_index (menu, Context, check, oldcount, index_hint);
495 /* notify the user of new mail */
496 if (check == M_REOPENED)
498 ("Mailbox was externally modified. Flags may be wrong."));
499 else if (check == M_NEW_MAIL) {
500 /* on new mail: redraw sidebar */
501 sidebar_draw (CurrentMenu);
502 mutt_message (_("New mail in this mailbox."));
504 if (option (OPTBEEPNEW))
507 else if (check == M_FLAGS)
508 mutt_message (_("Mailbox was externally modified."));
510 /* avoid the message being overwritten by buffy */
513 menu->redraw = REDRAW_FULL;
514 menu->max = Context->vcount;
516 set_option (OPTSEARCHINVALID);
522 imap_disallow_reopen (Context);
526 /* check for new mail in the incoming folders */
528 if ((newcount = buffy_check (0)) != oldcount) {
529 menu->redraw |= REDRAW_STATUS;
530 menu->redraw |= REDRAW_SIDEBAR;
532 if (do_buffy_notify) {
533 if (buffy_notify () && option (OPTBEEPNEW))
542 if (menu->redraw & REDRAW_SIDEBAR)
543 sidebar_draw (menu->menu);
544 if (menu->redraw & REDRAW_FULL) {
545 menu_redraw_full (menu);
546 sidebar_draw (menu->menu);
550 if (menu->menu == MENU_MAIN) {
551 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
552 menu_check_recenter (menu);
554 if (menu->redraw & REDRAW_INDEX) {
555 menu_redraw_index (menu);
556 menu->redraw |= REDRAW_STATUS;
558 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
559 menu_redraw_motion (menu);
560 else if (menu->redraw & REDRAW_CURRENT)
561 menu_redraw_current (menu);
564 if (menu->redraw & REDRAW_STATUS) {
565 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
566 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
567 sidebar_draw_frames();
568 SETCOLOR (MT_COLOR_STATUS);
569 BKGDSET (MT_COLOR_STATUS);
570 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
571 mutt_paddstr (COLS-SW, buf);
572 SETCOLOR (MT_COLOR_NORMAL);
573 BKGDSET (MT_COLOR_NORMAL);
574 sidebar_set_buffystats (Context);
575 menu->redraw &= ~REDRAW_STATUS;
576 if (option (OPTXTERMSETTITLES)) {
577 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
578 mutt_xterm_set_title (buf);
579 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
580 mutt_xterm_set_icon (buf);
585 if (menu->current < menu->max)
586 menu->oldcurrent = menu->current;
588 menu->oldcurrent = -1;
590 if (option (OPTARROWCURSOR))
591 move (menu->current - menu->top + menu->offset, 2);
592 else if (option (OPTBRAILLEFRIENDLY))
593 move (menu->current - menu->top + menu->offset, 0);
595 move (menu->current - menu->top + menu->offset, COLS - 1);
598 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
601 mutt_resize_screen ();
602 menu->redraw = REDRAW_FULL;
603 menu->menu = MENU_MAIN;
605 menu->top = 0; /* so we scroll the right amount */
607 * force a real complete redraw. clrtobot() doesn't seem to be able
608 * to handle every case without this.
610 clearok (stdscr, TRUE);
615 op = km_dokey (MENU_MAIN);
617 debug_print (4, ("Got op %d\n", op));
620 continue; /* either user abort or timeout */
624 /* special handling for the tag-prefix function */
625 if (op == OP_TAG_PREFIX) {
627 mutt_error (_("No mailbox is open."));
632 if (!Context->tagged) {
633 mutt_error (_("No tagged messages."));
639 /* give visual indication that the next command is a tag- command */
640 mvaddstr (LINES - 1, 0, "tag-");
643 /* get the real command */
644 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
645 /* abort tag sequence */
646 CLEARLINE (LINES - 1);
650 else if (option (OPTAUTOTAG) && Context && Context->tagged)
653 if (op == OP_TAG_PREFIX_COND) {
655 mutt_error (_("No mailbox is open."));
660 if (!Context->tagged) {
663 while (UngetCount > 0) {
665 if (tmp.op == OP_END_COND)
668 mutt_message (_("Nothing to do."));
674 /* give visual indication that the next command is a tag- command */
675 mvaddstr (LINES - 1, 0, "tag-");
678 /* get the real command */
679 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
680 /* abort tag sequence */
681 CLEARLINE (LINES - 1);
689 if (menu->current < menu->max)
690 menu->oldcurrent = menu->current;
692 menu->oldcurrent = -1;
694 mutt_curs_set (1); /* fallback from the pager */
698 unset_option (OPTNEWS); /* for any case */
703 /* ----------------------------------------------------------------------
708 menu_bottom_page (menu);
711 menu_first_entry (menu);
714 menu_middle_page (menu);
720 menu_half_down (menu);
723 menu_next_line (menu);
726 menu_prev_line (menu);
729 menu_next_page (menu);
732 menu_prev_page (menu);
735 menu_last_entry (menu);
738 menu_top_page (menu);
741 menu_current_top (menu);
743 case OP_CURRENT_MIDDLE:
744 menu_current_middle (menu);
746 case OP_CURRENT_BOTTOM:
747 menu_current_bottom (menu);
754 if (Context->magic == M_NNTP) {
757 if (op == OP_GET_MESSAGE) {
759 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
764 LIST *ref = CURHDR->env->references;
767 mutt_error (_("Article has no parent reference!"));
771 strfcpy (buf, ref->data, sizeof (buf));
773 if (!Context->id_hash)
774 Context->id_hash = mutt_make_id_hash (Context);
775 if ((h = hash_find (Context->id_hash, buf))) {
776 if (h->virtual != -1) {
777 menu->current = h->virtual;
778 menu->redraw = REDRAW_MOTION_RESYNCH;
780 else if (h->collapsed) {
781 mutt_uncollapse_thread (Context, h);
782 mutt_set_virtual (Context);
783 menu->current = h->virtual;
784 menu->redraw = REDRAW_MOTION_RESYNCH;
787 mutt_error (_("Message not visible in limited view."));
790 if (nntp_check_msgid (Context, buf) == 0) {
791 h = Context->hdrs[Context->msgcount - 1];
792 mutt_sort_headers (Context, 0);
793 menu->current = h->virtual;
794 menu->redraw = REDRAW_FULL;
797 mutt_error (_("Article %s not found on server"), buf);
802 case OP_GET_CHILDREN:
803 case OP_RECONSTRUCT_THREAD:
805 if (Context->magic == M_NNTP) {
807 int old = CURHDR->index, i;
809 if (!CURHDR->env->message_id) {
810 mutt_error (_("No Message-ID. Unable to perform operation"));
815 if (!Context->id_hash)
816 Context->id_hash = mutt_make_id_hash (Context);
817 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
819 if (op == OP_RECONSTRUCT_THREAD) {
820 LIST *ref = CURHDR->env->references;
823 nntp_check_msgid (Context, ref->data);
824 /* the last msgid in References is the root message */
826 strfcpy (buf, ref->data, sizeof (buf));
830 mutt_message (_("Check for children of message..."));
832 if (nntp_check_children (Context, buf) == 0) {
833 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
834 h = hash_find (Context->id_hash, buf);
835 /* if the root message was retrieved, move to it */
837 menu->current = h->virtual;
838 else /* try to restore old position */
839 for (i = 0; i < Context->msgcount; i++)
840 if (Context->hdrs[i]->index == old) {
841 menu->current = Context->hdrs[i]->virtual;
842 /* As an added courtesy, recenter the menu
843 * with the current entry at the middle of the screen */
844 menu_check_recenter (menu);
845 menu_current_middle (menu);
848 menu->redraw = REDRAW_FULL;
858 if (isdigit (LastKey))
859 mutt_ungetch (LastKey, 0);
861 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
865 if (!isdigit ((unsigned char) buf[0])) {
866 mutt_error (_("Argument must be a message number."));
872 if (i > 0 && i <= Context->msgcount) {
873 for (j = i - 1; j < Context->msgcount; j++) {
874 if (Context->hdrs[j]->virtual != -1)
877 if (j >= Context->msgcount) {
878 for (j = i - 2; j >= 0; j--) {
879 if (Context->hdrs[j]->virtual != -1)
885 menu->current = Context->hdrs[j]->virtual;
886 if (menu->menu == MENU_PAGER) {
887 op = OP_DISPLAY_MESSAGE;
891 menu->redraw = REDRAW_MOTION;
894 mutt_error (_("That message is not visible."));
897 mutt_error (_("Invalid message number."));
901 /* --------------------------------------------------------------------
902 * `index' specific commands
905 case OP_MAIN_DELETE_PATTERN:
911 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
914 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
915 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
919 case OP_MAIN_FETCH_MAIL:
923 menu->redraw = REDRAW_FULL;
929 mutt_help (MENU_MAIN);
930 menu->redraw = REDRAW_FULL;
933 case OP_MAIN_SHOW_LIMIT:
935 if (!Context->pattern)
936 mutt_message (_("No limit pattern is in effect."));
941 /* i18n: ask for a limit to apply */
942 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
943 mutt_message ("%s", buf);
951 menu->oldcurrent = (Context->vcount && menu->current >= 0
953 Context->vcount) ? CURHDR->index : -1;
954 if (op == OP_TOGGLE_READ) {
955 char buf[LONG_STRING];
957 if (!Context->pattern
958 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
959 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
960 Context->pattern ? Context->pattern : ".*");
961 set_option (OPTHIDEREAD);
964 strfcpy (buf, Context->pattern + 8, sizeof (buf));
965 if (!*buf || strncmp (buf, ".*", 2) == 0)
966 snprintf (buf, sizeof (buf), "~A");
967 unset_option (OPTHIDEREAD);
969 mem_free (&Context->pattern);
970 Context->pattern = str_dup (buf);
972 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
973 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
975 if (menu->oldcurrent >= 0) {
976 /* try to find what used to be the current message */
978 for (i = 0; i < Context->vcount; i++)
979 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
983 if (menu->current < 0)
988 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
989 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
990 mutt_draw_tree (Context);
991 menu->redraw = REDRAW_FULL;
993 if (Context->pattern)
994 mutt_message _("To view all messages, limit to \"all\".");
1005 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1008 oldcount = Context ? Context->msgcount : 0;
1011 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1014 if (check == M_NEW_MAIL || check == M_REOPENED)
1015 update_index (menu, Context, check, oldcount, index_hint);
1017 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1018 set_option (OPTSEARCHINVALID);
1025 clearok (stdscr, TRUE);
1026 menu->redraw = REDRAW_FULL;
1030 case OP_SEARCH_REVERSE:
1031 case OP_SEARCH_NEXT:
1032 case OP_SEARCH_OPPOSITE:
1036 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1037 menu->current = menu->oldcurrent;
1039 menu->redraw = REDRAW_MOTION;
1043 case OP_SORT_REVERSE:
1045 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1046 if (Context && Context->msgcount) {
1047 resort_index (menu);
1048 set_option (OPTSEARCHINVALID);
1057 if (tag && !option (OPTAUTOTAG)) {
1058 for (j = 0; j < Context->vcount; j++)
1059 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1060 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1063 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1064 Context->last_tag = CURHDR->tagged ? CURHDR :
1065 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1066 ? NULL : Context->last_tag);
1067 menu->redraw = REDRAW_STATUS;
1068 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1070 menu->redraw |= REDRAW_MOTION_RESYNCH;
1073 menu->redraw |= REDRAW_CURRENT;
1077 case OP_MAIN_TAG_PATTERN:
1081 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1082 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1085 case OP_MAIN_UNDELETE_PATTERN:
1091 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1093 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1095 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1098 case OP_MAIN_UNTAG_PATTERN:
1102 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1103 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1106 /* --------------------------------------------------------------------
1107 * The following operations can be performed inside of the pager.
1111 case OP_MAIN_IMAP_FETCH:
1112 if (Context->magic == M_IMAP)
1113 imap_check_mailbox (Context, &index_hint, 1);
1117 case OP_MAIN_SYNC_FOLDER:
1119 if (Context && !Context->msgcount)
1126 int oldvcount = Context->vcount;
1127 int oldcount = Context->msgcount;
1131 /* calculate the number of messages _above_ the cursor,
1132 * so we can keep the cursor on the current message
1134 for (j = 0; j <= menu->current; j++) {
1135 if (Context->hdrs[Context->v2r[j]]->deleted)
1139 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1140 if (Context->vcount != oldvcount)
1141 menu->current -= dcount;
1142 set_option (OPTSEARCHINVALID);
1144 else if (check == M_NEW_MAIL || check == M_REOPENED)
1145 update_index (menu, Context, check, oldcount, index_hint);
1148 * do a sanity check even if mx_sync_mailbox failed.
1151 if (menu->current < 0 || menu->current >= Context->vcount)
1152 menu->current = ci_first_message ();
1155 /* check for a fatal error, or all messages deleted */
1157 mem_free (&Context);
1159 /* if we were in the pager, redisplay the message */
1160 if (menu->menu == MENU_PAGER) {
1161 op = OP_DISPLAY_MESSAGE;
1165 menu->redraw = REDRAW_FULL;
1168 case OP_SIDEBAR_OPEN:
1169 case OP_MAIN_CHANGE_FOLDER:
1170 case OP_MAIN_CHANGE_FOLDER_READONLY:
1172 case OP_MAIN_CHANGE_GROUP:
1173 case OP_MAIN_CHANGE_GROUP_READONLY:
1175 if (attach_msg || option (OPTREADONLY) ||
1177 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1179 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1185 cp = _("Open mailbox in read-only mode");
1187 cp = _("Open mailbox");
1191 unset_option (OPTNEWS);
1192 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1193 set_option (OPTNEWS);
1194 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1197 cp = _("Open newsgroup in read-only mode");
1199 cp = _("Open newsgroup");
1200 nntp_buffy (buf, sizeof (buf));
1205 if (Context && Context->path)
1206 strncpy (buf, Context->path, sizeof (buf));
1207 if (op != OP_SIDEBAR_OPEN)
1208 buffy_next (buf, sizeof (buf));
1211 if (op == OP_SIDEBAR_OPEN) {
1212 strncpy (buf, NONULL(sidebar_get_current ()), sizeof (buf));
1214 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1215 if (menu->menu == MENU_PAGER) {
1216 op = OP_DISPLAY_MESSAGE;
1222 CLEARLINE (LINES - 1);
1227 if (option (OPTNEWS)) {
1228 unset_option (OPTNEWS);
1229 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1233 mutt_expand_path (buf, sizeof (buf));
1234 if (mx_get_magic (buf) <= 0) {
1235 mutt_error (_("%s is not a mailbox."), buf);
1238 str_replace (&CurrentFolder, buf);
1243 #ifdef USE_COMPRESSED
1244 if (Context->compressinfo && Context->realpath)
1245 str_replace (&LastFolder, Context->realpath);
1249 str_replace (&LastFolder, Context->path);
1250 oldcount = Context ? Context->msgcount : 0;
1252 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1253 if (check == M_NEW_MAIL || check == M_REOPENED)
1254 update_index (menu, Context, check, oldcount, index_hint);
1256 set_option (OPTSEARCHINVALID);
1257 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1260 mem_free (&Context);
1265 /* Set CurrentMenu to MENU_MAIN before executing any folder
1266 * hooks so that all the index menu functions are available to
1270 CurrentMenu = MENU_MAIN;
1271 mutt_folder_hook (buf);
1273 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1274 menu->current = ci_first_message ();
1278 sidebar_set_current (buf);
1281 /* buffy_check() must be done with mail-reader mode! */
1282 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1284 && (Context->magic ==
1285 M_NNTP)) ? IndexNewsHelp :
1288 mutt_clear_error ();
1289 buffy_check (1); /* force the buffy check after we have changed
1291 menu->redraw = REDRAW_FULL;
1292 set_option (OPTSEARCHINVALID);
1295 case OP_DISPLAY_MESSAGE:
1296 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1301 * toggle the weeding of headers so that a user can press the key
1302 * again while reading the message.
1304 if (op == OP_DISPLAY_HEADERS)
1305 toggle_option (OPTWEED);
1307 unset_option (OPTNEEDRESORT);
1309 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1310 mutt_uncollapse_thread (Context, CURHDR);
1311 mutt_set_virtual (Context);
1312 if (option (OPTUNCOLLAPSEJUMP))
1313 menu->current = mutt_thread_next_unread (Context, CURHDR);
1316 if (option (OPTPGPAUTODEC) &&
1317 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1318 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1320 if ((op = mutt_display_message (CURHDR)) == -1) {
1321 unset_option (OPTNEEDRESORT);
1325 menu->menu = MENU_PAGER;
1326 menu->oldcurrent = menu->current;
1332 if (menu->menu == MENU_MAIN && attach_msg) {
1337 if ((menu->menu == MENU_MAIN)
1338 && (query_quadoption (OPT_QUIT,
1339 _("Exit Mutt-ng without saving?")) == M_YES))
1342 mx_fastclose_mailbox (Context);
1343 mem_free (&Context);
1354 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1355 /* if we were in the pager, redisplay the message */
1356 if (menu->menu == MENU_PAGER) {
1357 op = OP_DISPLAY_MESSAGE;
1361 menu->redraw = REDRAW_CURRENT;
1364 case OP_MAIN_BREAK_THREAD:
1370 if ((Sort & SORT_MASK) != SORT_THREADS)
1371 mutt_error (_("Threading is not enabled."));
1375 HEADER *oldcur = CURHDR;
1377 mutt_break_thread (CURHDR);
1378 mutt_sort_headers (Context, 1);
1379 menu->current = oldcur->virtual;
1382 Context->changed = 1;
1383 mutt_message _("Thread broken");
1385 if (menu->menu == MENU_PAGER) {
1386 op = OP_DISPLAY_MESSAGE;
1390 menu->redraw |= REDRAW_INDEX;
1394 case OP_MAIN_LINK_THREADS:
1400 if ((Sort & SORT_MASK) != SORT_THREADS)
1401 mutt_error (_("Threading is not enabled."));
1403 else if (!CURHDR->env->message_id)
1404 mutt_error (_("No Message-ID: header available to link thread"));
1406 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1407 mutt_error (_("First, please tag a message to be linked here"));
1410 HEADER *oldcur = CURHDR;
1412 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1414 mutt_sort_headers (Context, 1);
1415 menu->current = oldcur->virtual;
1417 Context->changed = 1;
1418 mutt_message _("Threads linked");
1421 mutt_error (_("No thread linked"));
1424 if (menu->menu == MENU_PAGER) {
1425 op = OP_DISPLAY_MESSAGE;
1429 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1432 case OP_MAIN_NEXT_UNDELETED:
1436 if (menu->current >= Context->vcount - 1) {
1437 if (menu->menu == MENU_MAIN)
1438 mutt_error (_("You are on the last message."));
1442 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1443 menu->current = menu->oldcurrent;
1444 if (menu->menu == MENU_MAIN)
1445 mutt_error (_("No undeleted messages."));
1447 else if (menu->menu == MENU_PAGER) {
1448 op = OP_DISPLAY_MESSAGE;
1452 menu->redraw = REDRAW_MOTION;
1459 if (menu->current >= Context->vcount - 1) {
1460 if (menu->menu == MENU_MAIN)
1461 mutt_error (_("You are on the last message."));
1466 if (menu->menu == MENU_PAGER) {
1467 op = OP_DISPLAY_MESSAGE;
1471 menu->redraw = REDRAW_MOTION;
1474 case OP_MAIN_PREV_UNDELETED:
1478 if (menu->current < 1) {
1479 mutt_error (_("You are on the first message."));
1483 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1484 menu->current = menu->oldcurrent;
1485 if (menu->menu == MENU_MAIN)
1486 mutt_error (_("No undeleted messages."));
1488 else if (menu->menu == MENU_PAGER) {
1489 op = OP_DISPLAY_MESSAGE;
1493 menu->redraw = REDRAW_MOTION;
1500 if (menu->current < 1) {
1501 if (menu->menu == MENU_MAIN)
1502 mutt_error (_("You are on the first message."));
1507 if (menu->menu == MENU_PAGER) {
1508 op = OP_DISPLAY_MESSAGE;
1512 menu->redraw = REDRAW_MOTION;
1515 case OP_DECRYPT_COPY:
1516 case OP_DECRYPT_SAVE:
1520 case OP_COPY_MESSAGE:
1522 case OP_DECODE_COPY:
1523 case OP_DECODE_SAVE:
1526 if (mutt_save_message (tag ? NULL : CURHDR,
1527 (op == OP_DECRYPT_SAVE) ||
1528 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1529 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1530 (op == OP_DECRYPT_SAVE)
1531 || (op == OP_DECRYPT_COPY)
1532 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1539 menu->redraw |= REDRAW_INDEX;
1540 else if (option (OPTRESOLVE)) {
1541 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1542 menu->current = menu->oldcurrent;
1543 menu->redraw |= REDRAW_CURRENT;
1546 menu->redraw |= REDRAW_MOTION_RESYNCH;
1549 menu->redraw |= REDRAW_CURRENT;
1553 case OP_MAIN_NEXT_NEW:
1554 case OP_MAIN_NEXT_UNREAD:
1555 case OP_MAIN_PREV_NEW:
1556 case OP_MAIN_PREV_UNREAD:
1557 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1558 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1561 int first_unread = -1;
1569 for (j = 0; j != Context->vcount; j++) {
1570 #define CURHDRi Context->hdrs[Context->v2r[i]]
1571 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1572 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1574 if (i > Context->vcount - 1) {
1575 mutt_message _("Search wrapped to top.");
1583 mutt_message _("Search wrapped to bottom.");
1585 i = Context->vcount - 1;
1589 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1590 if (UNREAD (CURHDRi) && first_unread == -1)
1592 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1595 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1596 if (first_unread == -1)
1598 if ((!CURHDRi->old) && first_new == -1)
1602 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1605 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1606 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1607 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1612 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1613 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1614 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1616 menu->current = first_new;
1617 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1618 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1619 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1620 && first_unread != -1)
1621 menu->current = first_unread;
1623 if (menu->current == -1) {
1624 menu->current = menu->oldcurrent;
1625 mutt_error ("%s%s.",
1626 (op == OP_MAIN_NEXT_NEW
1628 OP_MAIN_PREV_NEW) ? _("No new messages") :
1629 _("No unread messages"),
1630 Context->pattern ? _(" in this limited view") : "");
1632 else if (menu->menu == MENU_PAGER) {
1633 op = OP_DISPLAY_MESSAGE;
1637 menu->redraw = REDRAW_MOTION;
1640 case OP_FLAG_MESSAGE:
1646 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1649 for (j = 0; j < Context->vcount; j++) {
1650 if (Context->hdrs[Context->v2r[j]]->tagged)
1651 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1652 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1655 menu->redraw |= REDRAW_INDEX;
1658 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1659 if (option (OPTRESOLVE)) {
1660 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1661 menu->current = menu->oldcurrent;
1662 menu->redraw = REDRAW_CURRENT;
1665 menu->redraw = REDRAW_MOTION_RESYNCH;
1668 menu->redraw = REDRAW_CURRENT;
1670 menu->redraw |= REDRAW_STATUS;
1679 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1682 for (j = 0; j < Context->vcount; j++) {
1683 if (Context->hdrs[Context->v2r[j]]->tagged) {
1684 if (Context->hdrs[Context->v2r[j]]->read ||
1685 Context->hdrs[Context->v2r[j]]->old)
1686 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1689 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1693 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1696 if (CURHDR->read || CURHDR->old)
1697 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1699 mutt_set_flag (Context, CURHDR, M_READ, 1);
1701 if (option (OPTRESOLVE)) {
1702 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1703 menu->current = menu->oldcurrent;
1704 menu->redraw = REDRAW_CURRENT;
1707 menu->redraw = REDRAW_MOTION_RESYNCH;
1710 menu->redraw = REDRAW_CURRENT;
1711 menu->redraw |= REDRAW_STATUS;
1715 case OP_TOGGLE_WRITE:
1718 if (mx_toggle_write (Context) == 0)
1719 menu->redraw |= REDRAW_STATUS;
1722 case OP_MAIN_NEXT_THREAD:
1723 case OP_MAIN_NEXT_SUBTHREAD:
1724 case OP_MAIN_PREV_THREAD:
1725 case OP_MAIN_PREV_SUBTHREAD:
1730 case OP_MAIN_NEXT_THREAD:
1731 menu->current = mutt_next_thread (CURHDR);
1734 case OP_MAIN_NEXT_SUBTHREAD:
1735 menu->current = mutt_next_subthread (CURHDR);
1738 case OP_MAIN_PREV_THREAD:
1739 menu->current = mutt_previous_thread (CURHDR);
1742 case OP_MAIN_PREV_SUBTHREAD:
1743 menu->current = mutt_previous_subthread (CURHDR);
1747 if (menu->current < 0) {
1748 menu->current = menu->oldcurrent;
1749 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1750 mutt_error (_("No more threads."));
1753 mutt_error (_("You are on the first thread."));
1755 else if (menu->menu == MENU_PAGER) {
1756 op = OP_DISPLAY_MESSAGE;
1760 menu->redraw = REDRAW_MOTION;
1763 case OP_MAIN_PARENT_MESSAGE:
1768 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1769 menu->current = menu->oldcurrent;
1771 else if (menu->menu == MENU_PAGER) {
1772 op = OP_DISPLAY_MESSAGE;
1776 menu->redraw = REDRAW_MOTION;
1779 case OP_MAIN_SET_FLAG:
1780 case OP_MAIN_CLEAR_FLAG:
1786 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1788 menu->redraw = REDRAW_STATUS;
1790 menu->redraw |= REDRAW_INDEX;
1791 else if (option (OPTRESOLVE)) {
1792 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1793 menu->current = menu->oldcurrent;
1794 menu->redraw |= REDRAW_CURRENT;
1797 menu->redraw |= REDRAW_MOTION_RESYNCH;
1800 menu->redraw |= REDRAW_CURRENT;
1804 case OP_MAIN_COLLAPSE_THREAD:
1808 if ((Sort & SORT_MASK) != SORT_THREADS) {
1809 mutt_error (_("Threading is not enabled."));
1814 if (CURHDR->collapsed) {
1815 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1816 mutt_set_virtual (Context);
1817 if (option (OPTUNCOLLAPSEJUMP))
1818 menu->current = mutt_thread_next_unread (Context, CURHDR);
1820 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1821 menu->current = mutt_collapse_thread (Context, CURHDR);
1822 mutt_set_virtual (Context);
1825 mutt_error (_("Thread contains unread messages."));
1830 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1834 case OP_MAIN_COLLAPSE_ALL:
1838 if ((Sort & SORT_MASK) != SORT_THREADS) {
1839 mutt_error (_("Threading is not enabled."));
1846 THREAD *thread, *top;
1849 if (CURHDR->collapsed)
1850 final = mutt_uncollapse_thread (Context, CURHDR);
1851 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1852 final = mutt_collapse_thread (Context, CURHDR);
1854 final = CURHDR->virtual;
1856 base = Context->hdrs[Context->v2r[final]];
1858 top = Context->tree;
1859 Context->collapsed = !Context->collapsed;
1860 while ((thread = top) != NULL) {
1861 while (!thread->message)
1862 thread = thread->child;
1863 h = thread->message;
1865 if (h->collapsed != Context->collapsed) {
1867 mutt_uncollapse_thread (Context, h);
1868 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1869 mutt_collapse_thread (Context, h);
1874 mutt_set_virtual (Context);
1875 for (j = 0; j < Context->vcount; j++) {
1876 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1882 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1886 /* --------------------------------------------------------------------
1887 * These functions are invoked directly from the internal-pager
1890 case OP_BOUNCE_MESSAGE:
1895 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1898 case OP_CREATE_ALIAS:
1900 mutt_create_alias (Context
1901 && Context->vcount ? CURHDR->env : NULL, NULL);
1902 MAYBE_REDRAW (menu->redraw);
1903 menu->redraw |= REDRAW_CURRENT;
1908 mutt_query_menu (NULL, 0);
1909 MAYBE_REDRAW (menu->redraw);
1912 case OP_PURGE_MESSAGE:
1919 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1922 mutt_tag_set_flag (M_DELETE, 1);
1923 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1924 if (option (OPTDELETEUNTAG))
1925 mutt_tag_set_flag (M_TAG, 0);
1926 menu->redraw = REDRAW_INDEX;
1929 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1930 mutt_set_flag (Context, CURHDR, M_PURGED,
1931 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1932 if (option (OPTDELETEUNTAG))
1933 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1934 if (option (OPTRESOLVE)) {
1935 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1936 menu->current = menu->oldcurrent;
1937 menu->redraw = REDRAW_CURRENT;
1939 else if (menu->menu == MENU_PAGER) {
1940 op = OP_DISPLAY_MESSAGE;
1944 menu->redraw |= REDRAW_MOTION_RESYNCH;
1947 menu->redraw = REDRAW_CURRENT;
1949 menu->redraw |= REDRAW_STATUS;
1952 case OP_DELETE_THREAD:
1953 case OP_DELETE_SUBTHREAD:
1959 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1961 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1962 op == OP_DELETE_THREAD ? 0 : 1);
1965 if (option (OPTDELETEUNTAG))
1966 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1967 op == OP_DELETE_THREAD ? 0 : 1);
1968 if (option (OPTRESOLVE))
1969 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1970 menu->current = menu->oldcurrent;
1971 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1977 if (Context && Context->magic == M_NNTP) {
1978 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1979 ((NNTP_DATA *) Context->data)->group))
1980 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1985 case OP_DISPLAY_ADDRESS:
1989 mutt_display_address (CURHDR->env);
1992 case OP_ENTER_COMMAND:
1994 CurrentMenu = MENU_MAIN;
1995 mutt_enter_command ();
1996 mutt_check_rescore (Context);
1997 if (option (OPTFORCEREDRAWINDEX))
1998 menu->redraw = REDRAW_FULL;
1999 unset_option (OPTFORCEREDRAWINDEX);
2000 unset_option (OPTFORCEREDRAWPAGER);
2003 case OP_EDIT_MESSAGE:
2010 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
2012 if (option (OPTPGPAUTODEC)
2013 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2014 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2015 mutt_edit_message (Context, tag ? NULL : CURHDR);
2016 menu->redraw = REDRAW_FULL;
2020 case OP_FORWARD_MESSAGE:
2026 if (option (OPTPGPAUTODEC) &&
2027 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2028 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2029 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2030 menu->redraw = REDRAW_FULL;
2034 case OP_FORGET_PASSPHRASE:
2035 crypt_forget_passphrase ();
2038 case OP_GROUP_REPLY:
2044 if (option (OPTPGPAUTODEC) &&
2045 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2046 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2048 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2049 tag ? NULL : CURHDR);
2050 menu->redraw = REDRAW_FULL;
2059 if (option (OPTPGPAUTODEC) &&
2060 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2061 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2063 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2064 tag ? NULL : CURHDR);
2065 menu->redraw = REDRAW_FULL;
2071 ci_send_message (0, NULL, NULL, Context, NULL);
2072 menu->redraw = REDRAW_FULL;
2076 if (!(WithCrypto & APPLICATION_PGP))
2079 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2080 menu->redraw = REDRAW_FULL;
2084 case OP_EXTRACT_KEYS:
2089 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2090 menu->redraw = REDRAW_FULL;
2094 case OP_CHECK_TRADITIONAL:
2095 if (!(WithCrypto & APPLICATION_PGP))
2099 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2100 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2102 if (menu->menu == MENU_PAGER) {
2103 op = OP_DISPLAY_MESSAGE;
2112 mutt_pipe_message (tag ? NULL : CURHDR);
2114 /* in an IMAP folder index with imap_peek=no, piping could change
2115 * * new or old messages status to read. Redraw what's needed.
2117 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2118 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2121 MAYBE_REDRAW (menu->redraw);
2128 mutt_print_message (tag ? NULL : CURHDR);
2130 /* in an IMAP folder index with imap_peek=no, piping could change
2131 * * new or old messages status to read. Redraw what's needed.
2133 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2134 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2139 case OP_MAIN_READ_THREAD:
2140 case OP_MAIN_READ_SUBTHREAD:
2146 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2148 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2149 op == OP_MAIN_READ_THREAD ? 0 : 1);
2152 if (option (OPTRESOLVE)) {
2153 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2154 mutt_next_thread (CURHDR) :
2155 mutt_next_subthread (CURHDR))) == -1)
2156 menu->current = menu->oldcurrent;
2158 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2162 case OP_RECALL_MESSAGE:
2165 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2166 menu->redraw = REDRAW_FULL;
2176 for (j = 0; j < Context->vcount; j++) {
2177 if (Context->hdrs[Context->v2r[j]]->tagged)
2178 mutt_resend_message (NULL, Context,
2179 Context->hdrs[Context->v2r[j]]);
2183 mutt_resend_message (NULL, Context, CURHDR);
2185 menu->redraw = REDRAW_FULL;
2191 case OP_FORWARD_TO_GROUP:
2194 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2195 Context && Context->msgcount == 0) {
2196 mutt_error (_("There are no messages."));
2199 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2200 str_casecmp (CURHDR->env->followup_to, "poster") ||
2201 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2202 _("Reply by mail as poster prefers?")) !=
2204 if (Context && Context->magic == M_NNTP
2205 && !((NNTP_DATA *) Context->data)->allowed
2206 && query_quadoption (OPT_TOMODERATED,
2208 ("Posting to this group not allowed, may be moderated. Continue?"))
2212 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2215 if (op == OP_FOLLOWUP)
2216 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2217 tag ? NULL : CURHDR);
2219 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2220 tag ? NULL : CURHDR);
2222 menu->redraw = REDRAW_FULL;
2233 if (option (OPTPGPAUTODEC) &&
2234 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2235 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2237 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2238 menu->redraw = REDRAW_FULL;
2241 case OP_SHELL_ESCAPE:
2243 mutt_shell_escape ();
2244 MAYBE_REDRAW (menu->redraw);
2248 case OP_TAG_SUBTHREAD:
2252 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2253 op == OP_TAG_THREAD ? 0 : 1);
2256 if (option (OPTRESOLVE)) {
2257 menu->current = mutt_next_thread (CURHDR);
2259 if (menu->current == -1)
2260 menu->current = menu->oldcurrent;
2262 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2272 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2275 mutt_tag_set_flag (M_DELETE, 0);
2276 mutt_tag_set_flag (M_PURGED, 0);
2277 menu->redraw = REDRAW_INDEX;
2280 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2281 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2282 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2284 menu->redraw = REDRAW_MOTION_RESYNCH;
2287 menu->redraw = REDRAW_CURRENT;
2289 menu->redraw |= REDRAW_STATUS;
2292 case OP_UNDELETE_THREAD:
2293 case OP_UNDELETE_SUBTHREAD:
2299 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2301 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2302 op == OP_UNDELETE_THREAD ? 0 : 1)
2303 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2304 op == OP_UNDELETE_THREAD ? 0 : 1);
2307 if (option (OPTRESOLVE)) {
2308 if (op == OP_UNDELETE_THREAD)
2309 menu->current = mutt_next_thread (CURHDR);
2311 menu->current = mutt_next_subthread (CURHDR);
2313 if (menu->current == -1)
2314 menu->current = menu->oldcurrent;
2316 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2325 if (option (OPTFORCEBUFFYCHECK))
2328 menu->redraw = REDRAW_FULL;
2331 case OP_VIEW_ATTACHMENTS:
2334 mutt_view_attachments (CURHDR);
2335 if (CURHDR->attach_del)
2336 Context->changed = 1;
2337 menu->redraw = REDRAW_FULL;
2347 case OP_REBUILD_CACHE:
2348 mx_rebuild_cache ();
2351 case OP_SIDEBAR_SCROLL_UP:
2352 case OP_SIDEBAR_SCROLL_DOWN:
2353 case OP_SIDEBAR_NEXT:
2354 case OP_SIDEBAR_PREV:
2355 case OP_SIDEBAR_NEXT_NEW:
2356 case OP_SIDEBAR_PREV_NEW:
2357 sidebar_scroll (op, menu->menu);
2360 if (menu->menu == MENU_MAIN)
2361 km_error_key (MENU_MAIN);
2364 if (menu->menu == MENU_PAGER) {
2365 menu->menu = MENU_MAIN;
2366 menu->redraw = REDRAW_FULL;
2368 set_option (OPTWEED); /* turn header weeding back on. */
2378 /* Close all open IMAP connections */
2382 /* Close all open NNTP connections */
2390 mutt_menuDestroy (&menu);
2394 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2401 for (color = ColorIndexList; color; color = color->next)
2402 if (mutt_pattern_exec
2403 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2404 curhdr->pair = color->pair;
2407 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];