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)
114 extern const char *ReleaseDate;
115 extern size_t UngetCount;
117 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
120 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
121 int edgemsgno, reverse = Sort & SORT_REVERSE;
122 HEADER *h = Context->hdrs[Context->v2r[num]];
125 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
126 flag |= M_FORMAT_TREE; /* display the thread tree */
127 if (h->display_subject)
128 flag |= M_FORMAT_FORCESUBJ;
131 if (menu->top + menu->pagelen > menu->max)
132 edgemsgno = Context->v2r[menu->max - 1];
134 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
137 edgemsgno = Context->v2r[menu->top];
139 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
143 /* if no ancestor is visible on current screen, provisionally force
145 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
147 flag |= M_FORMAT_FORCESUBJ;
150 else if (tmp->message->virtual >= 0)
153 if (flag & M_FORMAT_FORCESUBJ) {
154 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
158 /* ...but if a previous sibling is available, don't force it */
159 if (reverse ? tmp->message->msgno >
160 edgemsgno : tmp->message->msgno < edgemsgno)
162 else if (tmp->message->virtual >= 0) {
163 flag &= ~M_FORMAT_FORCESUBJ;
171 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
174 int index_color (int index_no)
176 HEADER *h = Context->hdrs[Context->v2r[index_no]];
181 mutt_set_header_color (Context, h);
185 static int ci_next_undeleted (int msgno)
189 for (i = msgno + 1; i < Context->vcount; i++)
190 if (!Context->hdrs[Context->v2r[i]]->deleted)
195 static int ci_previous_undeleted (int msgno)
199 for (i = msgno - 1; i >= 0; i--)
200 if (!Context->hdrs[Context->v2r[i]]->deleted)
205 /* Return the index of the first new message, or failing that, the first
208 static int ci_first_message (void)
212 if (Context && Context->msgcount) {
213 for (i = 0; i < Context->vcount; i++) {
214 if (!Context->hdrs[Context->v2r[i]]->read &&
215 !Context->hdrs[Context->v2r[i]]->deleted) {
216 if (!Context->hdrs[Context->v2r[i]]->old)
225 /* If Sort is reverse and not threaded, the latest message is first.
226 * If Sort is threaded, the latest message is first iff exactly one
227 * of Sort and SortAux are reverse.
229 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
230 ((Sort & SORT_MASK) == SORT_THREADS &&
231 ((Sort ^ SortAux) & SORT_REVERSE)))
234 return (Context->vcount ? Context->vcount - 1 : 0);
239 /* This should be in mx.c, but it only gets used here. */
240 static int mx_toggle_write (CONTEXT * ctx)
246 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
251 if (ctx->dontwrite) {
253 mutt_message (_("Changes to folder will be written on folder exit."));
257 mutt_message (_("Changes to folder will not be written."));
263 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
264 int oldcount, int index_hint)
266 /* store pointers to the newly added messages */
267 HEADER **save_new = NULL;
270 /* take note of the current message */
272 if (menu->current < Context->vcount)
273 menu->oldcurrent = index_hint;
275 oldcount = 0; /* invalid message number! */
278 /* We are in a limited view. Check if the new message(s) satisfy
279 * the limit criteria. If they do, set their virtual msgno so that
280 * they will be visible in the limited view */
281 if (Context->pattern) {
282 #define THIS_BODY Context->hdrs[j]->content
283 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
284 if (mutt_pattern_exec
285 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
287 Context->hdrs[j]->virtual = Context->vcount;
288 Context->v2r[Context->vcount] = j;
289 Context->hdrs[j]->limited = 1;
292 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
298 /* save the list of new messages */
299 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
301 (HEADER **) mem_malloc (sizeof (HEADER *) *
302 (Context->msgcount - oldcount));
303 for (j = oldcount; j < Context->msgcount; j++)
304 save_new[j - oldcount] = Context->hdrs[j];
307 /* if the mailbox was reopened, need to rethread from scratch */
308 mutt_sort_headers (Context, (check == M_REOPENED));
310 /* uncollapse threads with new mail */
311 if ((Sort & SORT_MASK) == SORT_THREADS) {
312 if (check == M_REOPENED) {
315 Context->collapsed = 0;
317 for (h = Context->tree; h; h = h->next) {
318 for (j = h; !j->message; j = j->child);
319 mutt_uncollapse_thread (Context, j->message);
321 mutt_set_virtual (Context);
324 for (j = 0; j < Context->msgcount - oldcount; j++) {
327 for (k = 0; k < Context->msgcount; k++) {
328 HEADER *h = Context->hdrs[k];
330 if (h == save_new[j] && (!Context->pattern || h->limited))
331 mutt_uncollapse_thread (Context, h);
334 mem_free (&save_new);
335 mutt_set_virtual (Context);
341 /* restore the current message to the message it was pointing to */
342 for (j = 0; j < Context->vcount; j++) {
343 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
350 if (menu->current < 0)
351 menu->current = ci_first_message ();
354 static void resort_index (MUTTMENU * menu)
357 HEADER *current = CURHDR;
360 mutt_sort_headers (Context, 0);
361 /* Restore the current message */
363 for (i = 0; i < Context->vcount; i++) {
364 if (Context->hdrs[Context->v2r[i]] == current) {
370 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
371 menu->current = mutt_parent_message (Context, current);
373 if (menu->current < 0)
374 menu->current = ci_first_message ();
376 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
379 struct mapping_t IndexHelp[] = {
380 {N_("Quit"), OP_QUIT},
381 {N_("Del"), OP_DELETE},
382 {N_("Undel"), OP_UNDELETE},
383 {N_("Save"), OP_SAVE},
384 {N_("Mail"), OP_MAIL},
385 {N_("Reply"), OP_REPLY},
386 {N_("Group"), OP_GROUP_REPLY},
387 {N_("Help"), OP_HELP},
392 struct mapping_t IndexNewsHelp[] = {
393 {N_("Quit"), OP_QUIT},
394 {N_("Del"), OP_DELETE},
395 {N_("Undel"), OP_UNDELETE},
396 {N_("Save"), OP_SAVE},
397 {N_("Post"), OP_POST},
398 {N_("Followup"), OP_FOLLOWUP},
399 {N_("Catchup"), OP_CATCHUP},
400 {N_("Help"), OP_HELP},
405 /* This function handles the message index window as well as commands returned
406 * from the pager (MENU_PAGER).
408 int mutt_index_menu (void)
410 char buf[LONG_STRING], helpstr[SHORT_STRING];
413 int done = 0; /* controls when to exit the "event" loop */
415 int tag = 0; /* has the tag-prefix command been pressed? */
420 char *cp; /* temporary variable. */
421 int index_hint; /* used to restore cursor position */
422 int do_buffy_notify = 1;
423 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
424 int attach_msg = option (OPTATTACHMSG);
426 menu = mutt_new_menu ();
427 menu->menu = MENU_MAIN;
429 menu->pagelen = LINES - 3;
430 menu->make_entry = index_make_entry;
431 menu->color = index_color;
432 menu->current = ci_first_message ();
433 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
436 && (Context->magic ==
437 M_NNTP)) ? IndexNewsHelp :
442 buffy_check (1); /* force the buffy check after we enter the folder */
443 /* record folder we open to place sidebar indicator properly */
444 if (Context && Context->path)
445 sidebar_set_current (Context->path);
449 tag = 0; /* clear the tag-prefix */
451 menu->max = Context ? Context->vcount : 0;
452 oldcount = Context ? Context->msgcount : 0;
454 /* check if we need to resort the index because just about
455 * any 'op' below could do mutt_enter_command(), either here or
456 * from any new menu launched, and change $sort/$sort_aux
458 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
461 if (option (OPTREDRAWTREE) && Context && Context->msgcount
462 && (Sort & SORT_MASK) == SORT_THREADS) {
463 mutt_draw_tree (Context);
464 menu->redraw |= REDRAW_STATUS;
465 unset_option (OPTREDRAWTREE);
468 if (Context && !attach_msg) {
471 /* check for new mail in the mailbox. If nonzero, then something has
472 * changed about the file (either we got new mail or the file was
473 * modified underneath us.)
477 imap_allow_reopen (Context);
480 index_hint = (Context->vcount && menu->current >= 0
481 && menu->current < Context->vcount) ? CURHDR->index : 0;
483 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
484 if (!Context->path) {
485 /* fatal error occurred */
487 menu->redraw = REDRAW_FULL;
489 set_option (OPTSEARCHINVALID);
491 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
492 update_index (menu, Context, check, oldcount, index_hint);
494 /* notify the user of new mail */
495 if (check == M_REOPENED)
497 ("Mailbox was externally modified. Flags may be wrong."));
498 else if (check == M_NEW_MAIL) {
499 /* on new mail: redraw sidebar */
500 sidebar_draw (CurrentMenu);
501 mutt_message (_("New mail in this mailbox."));
503 if (option (OPTBEEPNEW))
506 else if (check == M_FLAGS)
507 mutt_message (_("Mailbox was externally modified."));
509 /* avoid the message being overwritten by buffy */
512 menu->redraw = REDRAW_FULL;
513 menu->max = Context->vcount;
515 set_option (OPTSEARCHINVALID);
521 imap_disallow_reopen (Context);
525 /* check for new mail in the incoming folders */
527 if ((newcount = buffy_check (0)) != oldcount) {
528 menu->redraw |= REDRAW_STATUS;
529 menu->redraw |= REDRAW_SIDEBAR;
531 if (do_buffy_notify) {
532 if (buffy_notify () && option (OPTBEEPNEW))
541 if (menu->redraw & REDRAW_SIDEBAR)
542 sidebar_draw (menu->menu);
543 if (menu->redraw & REDRAW_FULL) {
544 menu_redraw_full (menu);
545 sidebar_draw (menu->menu);
549 if (menu->menu == MENU_MAIN) {
550 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
551 menu_check_recenter (menu);
553 if (menu->redraw & REDRAW_INDEX) {
554 menu_redraw_index (menu);
555 menu->redraw |= REDRAW_STATUS;
557 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
558 menu_redraw_motion (menu);
559 else if (menu->redraw & REDRAW_CURRENT)
560 menu_redraw_current (menu);
563 if (menu->redraw & REDRAW_STATUS) {
565 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
567 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
568 SETCOLOR (MT_COLOR_STATUS);
569 BKGDSET (MT_COLOR_STATUS);
570 mutt_paddstr (COLS, buf);
571 SETCOLOR (MT_COLOR_NORMAL);
572 BKGDSET (MT_COLOR_NORMAL);
573 sidebar_set_buffystats (Context);
574 menu->redraw &= ~REDRAW_STATUS;
575 if (option (OPTXTERMSETTITLES)) {
576 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
577 mutt_xterm_set_title (buf);
578 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
579 mutt_xterm_set_icon (buf);
584 if (menu->current < menu->max)
585 menu->oldcurrent = menu->current;
587 menu->oldcurrent = -1;
589 if (option (OPTARROWCURSOR))
590 move (menu->current - menu->top + menu->offset, 2);
591 else if (option (OPTBRAILLEFRIENDLY))
592 move (menu->current - menu->top + menu->offset, 0);
594 move (menu->current - menu->top + menu->offset, COLS - 1);
597 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
600 mutt_resize_screen ();
601 menu->redraw = REDRAW_FULL;
602 menu->menu = MENU_MAIN;
604 menu->top = 0; /* so we scroll the right amount */
606 * force a real complete redraw. clrtobot() doesn't seem to be able
607 * to handle every case without this.
609 clearok (stdscr, TRUE);
614 op = km_dokey (MENU_MAIN);
616 debug_print (4, ("Got op %d\n", op));
619 continue; /* either user abort or timeout */
623 /* special handling for the tag-prefix function */
624 if (op == OP_TAG_PREFIX) {
626 mutt_error (_("No mailbox is open."));
631 if (!Context->tagged) {
632 mutt_error (_("No tagged messages."));
638 /* give visual indication that the next command is a tag- command */
639 mvaddstr (LINES - 1, 0, "tag-");
642 /* get the real command */
643 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
644 /* abort tag sequence */
645 CLEARLINE (LINES - 1);
649 else if (option (OPTAUTOTAG) && Context && Context->tagged)
652 if (op == OP_TAG_PREFIX_COND) {
654 mutt_error (_("No mailbox is open."));
659 if (!Context->tagged) {
662 while (UngetCount > 0) {
664 if (tmp.op == OP_END_COND)
667 mutt_message (_("Nothing to do."));
673 /* give visual indication that the next command is a tag- command */
674 mvaddstr (LINES - 1, 0, "tag-");
677 /* get the real command */
678 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
679 /* abort tag sequence */
680 CLEARLINE (LINES - 1);
688 if (menu->current < menu->max)
689 menu->oldcurrent = menu->current;
691 menu->oldcurrent = -1;
693 mutt_curs_set (1); /* fallback from the pager */
697 unset_option (OPTNEWS); /* for any case */
702 /* ----------------------------------------------------------------------
707 menu_bottom_page (menu);
710 menu_first_entry (menu);
713 menu_middle_page (menu);
719 menu_half_down (menu);
722 menu_next_line (menu);
725 menu_prev_line (menu);
728 menu_next_page (menu);
731 menu_prev_page (menu);
734 menu_last_entry (menu);
737 menu_top_page (menu);
740 menu_current_top (menu);
742 case OP_CURRENT_MIDDLE:
743 menu_current_middle (menu);
745 case OP_CURRENT_BOTTOM:
746 menu_current_bottom (menu);
753 if (Context->magic == M_NNTP) {
756 if (op == OP_GET_MESSAGE) {
758 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
763 LIST *ref = CURHDR->env->references;
766 mutt_error (_("Article has no parent reference!"));
770 strfcpy (buf, ref->data, sizeof (buf));
772 if (!Context->id_hash)
773 Context->id_hash = mutt_make_id_hash (Context);
774 if ((h = hash_find (Context->id_hash, buf))) {
775 if (h->virtual != -1) {
776 menu->current = h->virtual;
777 menu->redraw = REDRAW_MOTION_RESYNCH;
779 else if (h->collapsed) {
780 mutt_uncollapse_thread (Context, h);
781 mutt_set_virtual (Context);
782 menu->current = h->virtual;
783 menu->redraw = REDRAW_MOTION_RESYNCH;
786 mutt_error (_("Message not visible in limited view."));
789 if (nntp_check_msgid (Context, buf) == 0) {
790 h = Context->hdrs[Context->msgcount - 1];
791 mutt_sort_headers (Context, 0);
792 menu->current = h->virtual;
793 menu->redraw = REDRAW_FULL;
796 mutt_error (_("Article %s not found on server"), buf);
801 case OP_GET_CHILDREN:
802 case OP_RECONSTRUCT_THREAD:
804 if (Context->magic == M_NNTP) {
806 int old = CURHDR->index, i;
808 if (!CURHDR->env->message_id) {
809 mutt_error (_("No Message-ID. Unable to perform operation"));
814 if (!Context->id_hash)
815 Context->id_hash = mutt_make_id_hash (Context);
816 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
818 if (op == OP_RECONSTRUCT_THREAD) {
819 LIST *ref = CURHDR->env->references;
822 nntp_check_msgid (Context, ref->data);
823 /* the last msgid in References is the root message */
825 strfcpy (buf, ref->data, sizeof (buf));
829 mutt_message (_("Check for children of message..."));
831 if (nntp_check_children (Context, buf) == 0) {
832 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
833 h = hash_find (Context->id_hash, buf);
834 /* if the root message was retrieved, move to it */
836 menu->current = h->virtual;
837 else /* try to restore old position */
838 for (i = 0; i < Context->msgcount; i++)
839 if (Context->hdrs[i]->index == old) {
840 menu->current = Context->hdrs[i]->virtual;
841 /* As an added courtesy, recenter the menu
842 * with the current entry at the middle of the screen */
843 menu_check_recenter (menu);
844 menu_current_middle (menu);
847 menu->redraw = REDRAW_FULL;
857 if (isdigit (LastKey))
858 mutt_ungetch (LastKey, 0);
860 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
864 if (!isdigit ((unsigned char) buf[0])) {
865 mutt_error (_("Argument must be a message number."));
871 if (i > 0 && i <= Context->msgcount) {
872 for (j = i - 1; j < Context->msgcount; j++) {
873 if (Context->hdrs[j]->virtual != -1)
876 if (j >= Context->msgcount) {
877 for (j = i - 2; j >= 0; j--) {
878 if (Context->hdrs[j]->virtual != -1)
884 menu->current = Context->hdrs[j]->virtual;
885 if (menu->menu == MENU_PAGER) {
886 op = OP_DISPLAY_MESSAGE;
890 menu->redraw = REDRAW_MOTION;
893 mutt_error (_("That message is not visible."));
896 mutt_error (_("Invalid message number."));
900 /* --------------------------------------------------------------------
901 * `index' specific commands
904 case OP_MAIN_DELETE_PATTERN:
910 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
913 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
914 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
918 case OP_MAIN_FETCH_MAIL:
922 menu->redraw = REDRAW_FULL;
928 mutt_help (MENU_MAIN);
929 menu->redraw = REDRAW_FULL;
932 case OP_MAIN_SHOW_LIMIT:
934 if (!Context->pattern)
935 mutt_message (_("No limit pattern is in effect."));
940 /* i18n: ask for a limit to apply */
941 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
942 mutt_message ("%s", buf);
950 menu->oldcurrent = (Context->vcount && menu->current >= 0
952 Context->vcount) ? CURHDR->index : -1;
953 if (op == OP_TOGGLE_READ) {
954 char buf[LONG_STRING];
956 if (!Context->pattern
957 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
958 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
959 Context->pattern ? Context->pattern : ".*");
960 set_option (OPTHIDEREAD);
963 strfcpy (buf, Context->pattern + 8, sizeof (buf));
964 if (!*buf || strncmp (buf, ".*", 2) == 0)
965 snprintf (buf, sizeof (buf), "~A");
966 unset_option (OPTHIDEREAD);
968 mem_free (&Context->pattern);
969 Context->pattern = str_dup (buf);
971 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
972 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
974 if (menu->oldcurrent >= 0) {
975 /* try to find what used to be the current message */
977 for (i = 0; i < Context->vcount; i++)
978 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
982 if (menu->current < 0)
987 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
988 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
989 mutt_draw_tree (Context);
990 menu->redraw = REDRAW_FULL;
1002 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1005 oldcount = Context ? Context->msgcount : 0;
1008 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1011 if (check == M_NEW_MAIL || check == M_REOPENED)
1012 update_index (menu, Context, check, oldcount, index_hint);
1014 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1015 set_option (OPTSEARCHINVALID);
1022 clearok (stdscr, TRUE);
1023 menu->redraw = REDRAW_FULL;
1027 case OP_SEARCH_REVERSE:
1028 case OP_SEARCH_NEXT:
1029 case OP_SEARCH_OPPOSITE:
1033 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1034 menu->current = menu->oldcurrent;
1036 menu->redraw = REDRAW_MOTION;
1040 case OP_SORT_REVERSE:
1042 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1043 if (Context && Context->msgcount) {
1044 resort_index (menu);
1045 set_option (OPTSEARCHINVALID);
1054 if (tag && !option (OPTAUTOTAG)) {
1055 for (j = 0; j < Context->vcount; j++)
1056 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1057 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1060 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1061 Context->last_tag = CURHDR->tagged ? CURHDR :
1062 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1063 ? NULL : Context->last_tag);
1064 menu->redraw = REDRAW_STATUS;
1065 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1067 menu->redraw |= REDRAW_MOTION_RESYNCH;
1070 menu->redraw |= REDRAW_CURRENT;
1074 case OP_MAIN_TAG_PATTERN:
1078 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1079 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1082 case OP_MAIN_UNDELETE_PATTERN:
1088 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1090 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1092 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1095 case OP_MAIN_UNTAG_PATTERN:
1099 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1100 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1103 /* --------------------------------------------------------------------
1104 * The following operations can be performed inside of the pager.
1108 case OP_MAIN_IMAP_FETCH:
1109 if (Context->magic == M_IMAP)
1110 imap_check_mailbox (Context, &index_hint, 1);
1114 case OP_MAIN_SYNC_FOLDER:
1116 if (Context && !Context->msgcount)
1123 int oldvcount = Context->vcount;
1124 int oldcount = Context->msgcount;
1128 /* calculate the number of messages _above_ the cursor,
1129 * so we can keep the cursor on the current message
1131 for (j = 0; j <= menu->current; j++) {
1132 if (Context->hdrs[Context->v2r[j]]->deleted)
1136 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1137 if (Context->vcount != oldvcount)
1138 menu->current -= dcount;
1139 set_option (OPTSEARCHINVALID);
1141 else if (check == M_NEW_MAIL || check == M_REOPENED)
1142 update_index (menu, Context, check, oldcount, index_hint);
1145 * do a sanity check even if mx_sync_mailbox failed.
1148 if (menu->current < 0 || menu->current >= Context->vcount)
1149 menu->current = ci_first_message ();
1152 /* check for a fatal error, or all messages deleted */
1154 mem_free (&Context);
1156 /* if we were in the pager, redisplay the message */
1157 if (menu->menu == MENU_PAGER) {
1158 op = OP_DISPLAY_MESSAGE;
1162 menu->redraw = REDRAW_FULL;
1165 case OP_SIDEBAR_OPEN:
1166 case OP_MAIN_CHANGE_FOLDER:
1167 case OP_MAIN_CHANGE_FOLDER_READONLY:
1169 case OP_MAIN_CHANGE_GROUP:
1170 case OP_MAIN_CHANGE_GROUP_READONLY:
1172 if (attach_msg || option (OPTREADONLY) ||
1174 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1176 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1182 cp = _("Open mailbox in read-only mode");
1184 cp = _("Open mailbox");
1188 unset_option (OPTNEWS);
1189 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1190 set_option (OPTNEWS);
1191 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1194 cp = _("Open newsgroup in read-only mode");
1196 cp = _("Open newsgroup");
1197 nntp_buffy (buf, sizeof (buf));
1202 if (Context && Context->path)
1203 strncpy (buf, Context->path, sizeof (buf));
1204 if (op != OP_SIDEBAR_OPEN)
1205 buffy_next (buf, sizeof (buf));
1208 if (op == OP_SIDEBAR_OPEN) {
1209 strncpy (buf, NONULL(sidebar_get_current ()), sizeof (buf));
1211 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1212 if (menu->menu == MENU_PAGER) {
1213 op = OP_DISPLAY_MESSAGE;
1219 CLEARLINE (LINES - 1);
1224 if (option (OPTNEWS)) {
1225 unset_option (OPTNEWS);
1226 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1230 mutt_expand_path (buf, sizeof (buf));
1231 if (mx_get_magic (buf) <= 0) {
1232 mutt_error (_("%s is not a mailbox."), buf);
1235 str_replace (&CurrentFolder, buf);
1240 #ifdef USE_COMPRESSED
1241 if (Context->compressinfo && Context->realpath)
1242 str_replace (&LastFolder, Context->realpath);
1246 str_replace (&LastFolder, Context->path);
1247 oldcount = Context ? Context->msgcount : 0;
1249 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1250 if (check == M_NEW_MAIL || check == M_REOPENED)
1251 update_index (menu, Context, check, oldcount, index_hint);
1253 set_option (OPTSEARCHINVALID);
1254 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1257 mem_free (&Context);
1262 /* Set CurrentMenu to MENU_MAIN before executing any folder
1263 * hooks so that all the index menu functions are available to
1267 CurrentMenu = MENU_MAIN;
1268 mutt_folder_hook (buf);
1270 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1271 menu->current = ci_first_message ();
1275 sidebar_set_current (buf);
1278 /* buffy_check() must be done with mail-reader mode! */
1279 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1281 && (Context->magic ==
1282 M_NNTP)) ? IndexNewsHelp :
1285 mutt_clear_error ();
1286 buffy_check (1); /* force the buffy check after we have changed
1288 menu->redraw = REDRAW_FULL;
1289 set_option (OPTSEARCHINVALID);
1292 case OP_DISPLAY_MESSAGE:
1293 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1298 * toggle the weeding of headers so that a user can press the key
1299 * again while reading the message.
1301 if (op == OP_DISPLAY_HEADERS)
1302 toggle_option (OPTWEED);
1304 unset_option (OPTNEEDRESORT);
1306 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1307 mutt_uncollapse_thread (Context, CURHDR);
1308 mutt_set_virtual (Context);
1309 if (option (OPTUNCOLLAPSEJUMP))
1310 menu->current = mutt_thread_next_unread (Context, CURHDR);
1313 if (option (OPTPGPAUTODEC) &&
1314 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1315 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1317 if ((op = mutt_display_message (CURHDR)) == -1) {
1318 unset_option (OPTNEEDRESORT);
1322 menu->menu = MENU_PAGER;
1323 menu->oldcurrent = menu->current;
1329 if (menu->menu == MENU_MAIN && attach_msg) {
1334 if ((menu->menu == MENU_MAIN)
1335 && (query_quadoption (OPT_QUIT,
1336 _("Exit Mutt-ng without saving?")) == M_YES))
1339 mx_fastclose_mailbox (Context);
1340 mem_free (&Context);
1351 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1352 /* if we were in the pager, redisplay the message */
1353 if (menu->menu == MENU_PAGER) {
1354 op = OP_DISPLAY_MESSAGE;
1358 menu->redraw = REDRAW_CURRENT;
1361 case OP_MAIN_BREAK_THREAD:
1367 if ((Sort & SORT_MASK) != SORT_THREADS)
1368 mutt_error (_("Threading is not enabled."));
1372 HEADER *oldcur = CURHDR;
1374 mutt_break_thread (CURHDR);
1375 mutt_sort_headers (Context, 1);
1376 menu->current = oldcur->virtual;
1379 Context->changed = 1;
1380 mutt_message _("Thread broken");
1382 if (menu->menu == MENU_PAGER) {
1383 op = OP_DISPLAY_MESSAGE;
1387 menu->redraw |= REDRAW_INDEX;
1391 case OP_MAIN_LINK_THREADS:
1397 if ((Sort & SORT_MASK) != SORT_THREADS)
1398 mutt_error (_("Threading is not enabled."));
1400 else if (!CURHDR->env->message_id)
1401 mutt_error (_("No Message-ID: header available to link thread"));
1403 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1404 mutt_error (_("First, please tag a message to be linked here"));
1407 HEADER *oldcur = CURHDR;
1409 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1411 mutt_sort_headers (Context, 1);
1412 menu->current = oldcur->virtual;
1414 Context->changed = 1;
1415 mutt_message _("Threads linked");
1418 mutt_error (_("No thread linked"));
1421 if (menu->menu == MENU_PAGER) {
1422 op = OP_DISPLAY_MESSAGE;
1426 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1429 case OP_MAIN_NEXT_UNDELETED:
1433 if (menu->current >= Context->vcount - 1) {
1434 if (menu->menu == MENU_MAIN)
1435 mutt_error (_("You are on the last message."));
1439 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1440 menu->current = menu->oldcurrent;
1441 if (menu->menu == MENU_MAIN)
1442 mutt_error (_("No undeleted messages."));
1444 else if (menu->menu == MENU_PAGER) {
1445 op = OP_DISPLAY_MESSAGE;
1449 menu->redraw = REDRAW_MOTION;
1456 if (menu->current >= Context->vcount - 1) {
1457 if (menu->menu == MENU_MAIN)
1458 mutt_error (_("You are on the last message."));
1463 if (menu->menu == MENU_PAGER) {
1464 op = OP_DISPLAY_MESSAGE;
1468 menu->redraw = REDRAW_MOTION;
1471 case OP_MAIN_PREV_UNDELETED:
1475 if (menu->current < 1) {
1476 mutt_error (_("You are on the first message."));
1480 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1481 menu->current = menu->oldcurrent;
1482 if (menu->menu == MENU_MAIN)
1483 mutt_error (_("No undeleted messages."));
1485 else if (menu->menu == MENU_PAGER) {
1486 op = OP_DISPLAY_MESSAGE;
1490 menu->redraw = REDRAW_MOTION;
1497 if (menu->current < 1) {
1498 if (menu->menu == MENU_MAIN)
1499 mutt_error (_("You are on the first message."));
1504 if (menu->menu == MENU_PAGER) {
1505 op = OP_DISPLAY_MESSAGE;
1509 menu->redraw = REDRAW_MOTION;
1512 case OP_DECRYPT_COPY:
1513 case OP_DECRYPT_SAVE:
1517 case OP_COPY_MESSAGE:
1519 case OP_DECODE_COPY:
1520 case OP_DECODE_SAVE:
1523 if (mutt_save_message (tag ? NULL : CURHDR,
1524 (op == OP_DECRYPT_SAVE) ||
1525 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1526 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1527 (op == OP_DECRYPT_SAVE)
1528 || (op == OP_DECRYPT_COPY)
1529 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1536 menu->redraw |= REDRAW_INDEX;
1537 else if (option (OPTRESOLVE)) {
1538 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1539 menu->current = menu->oldcurrent;
1540 menu->redraw |= REDRAW_CURRENT;
1543 menu->redraw |= REDRAW_MOTION_RESYNCH;
1546 menu->redraw |= REDRAW_CURRENT;
1550 case OP_MAIN_NEXT_NEW:
1551 case OP_MAIN_NEXT_UNREAD:
1552 case OP_MAIN_PREV_NEW:
1553 case OP_MAIN_PREV_UNREAD:
1554 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1555 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1558 int first_unread = -1;
1566 for (j = 0; j != Context->vcount; j++) {
1567 #define CURHDRi Context->hdrs[Context->v2r[i]]
1568 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1569 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1571 if (i > Context->vcount - 1) {
1572 mutt_message _("Search wrapped to top.");
1580 mutt_message _("Search wrapped to bottom.");
1582 i = Context->vcount - 1;
1586 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1587 if (UNREAD (CURHDRi) && first_unread == -1)
1589 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1592 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1593 if (first_unread == -1)
1595 if ((!CURHDRi->old) && first_new == -1)
1599 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1602 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1603 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1604 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1609 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1610 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1611 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1613 menu->current = first_new;
1614 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1615 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1616 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1617 && first_unread != -1)
1618 menu->current = first_unread;
1620 if (menu->current == -1) {
1621 menu->current = menu->oldcurrent;
1622 mutt_error ("%s%s.",
1623 (op == OP_MAIN_NEXT_NEW
1625 OP_MAIN_PREV_NEW) ? _("No new messages") :
1626 _("No unread messages"),
1627 Context->pattern ? _(" in this limited view") : "");
1629 else if (menu->menu == MENU_PAGER) {
1630 op = OP_DISPLAY_MESSAGE;
1634 menu->redraw = REDRAW_MOTION;
1637 case OP_FLAG_MESSAGE:
1643 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1646 for (j = 0; j < Context->vcount; j++) {
1647 if (Context->hdrs[Context->v2r[j]]->tagged)
1648 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1649 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1652 menu->redraw |= REDRAW_INDEX;
1655 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1656 if (option (OPTRESOLVE)) {
1657 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1658 menu->current = menu->oldcurrent;
1659 menu->redraw = REDRAW_CURRENT;
1662 menu->redraw = REDRAW_MOTION_RESYNCH;
1665 menu->redraw = REDRAW_CURRENT;
1667 menu->redraw |= REDRAW_STATUS;
1676 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1679 for (j = 0; j < Context->vcount; j++) {
1680 if (Context->hdrs[Context->v2r[j]]->tagged) {
1681 if (Context->hdrs[Context->v2r[j]]->read ||
1682 Context->hdrs[Context->v2r[j]]->old)
1683 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1686 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1690 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1693 if (CURHDR->read || CURHDR->old)
1694 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1696 mutt_set_flag (Context, CURHDR, M_READ, 1);
1698 if (option (OPTRESOLVE)) {
1699 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1700 menu->current = menu->oldcurrent;
1701 menu->redraw = REDRAW_CURRENT;
1704 menu->redraw = REDRAW_MOTION_RESYNCH;
1707 menu->redraw = REDRAW_CURRENT;
1708 menu->redraw |= REDRAW_STATUS;
1712 case OP_TOGGLE_WRITE:
1715 if (mx_toggle_write (Context) == 0)
1716 menu->redraw |= REDRAW_STATUS;
1719 case OP_MAIN_NEXT_THREAD:
1720 case OP_MAIN_NEXT_SUBTHREAD:
1721 case OP_MAIN_PREV_THREAD:
1722 case OP_MAIN_PREV_SUBTHREAD:
1727 case OP_MAIN_NEXT_THREAD:
1728 menu->current = mutt_next_thread (CURHDR);
1731 case OP_MAIN_NEXT_SUBTHREAD:
1732 menu->current = mutt_next_subthread (CURHDR);
1735 case OP_MAIN_PREV_THREAD:
1736 menu->current = mutt_previous_thread (CURHDR);
1739 case OP_MAIN_PREV_SUBTHREAD:
1740 menu->current = mutt_previous_subthread (CURHDR);
1744 if (menu->current < 0) {
1745 menu->current = menu->oldcurrent;
1746 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1747 mutt_error (_("No more threads."));
1750 mutt_error (_("You are on the first thread."));
1752 else if (menu->menu == MENU_PAGER) {
1753 op = OP_DISPLAY_MESSAGE;
1757 menu->redraw = REDRAW_MOTION;
1760 case OP_MAIN_PARENT_MESSAGE:
1765 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1766 menu->current = menu->oldcurrent;
1768 else if (menu->menu == MENU_PAGER) {
1769 op = OP_DISPLAY_MESSAGE;
1773 menu->redraw = REDRAW_MOTION;
1776 case OP_MAIN_SET_FLAG:
1777 case OP_MAIN_CLEAR_FLAG:
1783 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1785 menu->redraw = REDRAW_STATUS;
1787 menu->redraw |= REDRAW_INDEX;
1788 else if (option (OPTRESOLVE)) {
1789 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1790 menu->current = menu->oldcurrent;
1791 menu->redraw |= REDRAW_CURRENT;
1794 menu->redraw |= REDRAW_MOTION_RESYNCH;
1797 menu->redraw |= REDRAW_CURRENT;
1801 case OP_MAIN_COLLAPSE_THREAD:
1805 if ((Sort & SORT_MASK) != SORT_THREADS) {
1806 mutt_error (_("Threading is not enabled."));
1811 if (CURHDR->collapsed) {
1812 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1813 mutt_set_virtual (Context);
1814 if (option (OPTUNCOLLAPSEJUMP))
1815 menu->current = mutt_thread_next_unread (Context, CURHDR);
1817 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1818 menu->current = mutt_collapse_thread (Context, CURHDR);
1819 mutt_set_virtual (Context);
1822 mutt_error (_("Thread contains unread messages."));
1827 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1831 case OP_MAIN_COLLAPSE_ALL:
1835 if ((Sort & SORT_MASK) != SORT_THREADS) {
1836 mutt_error (_("Threading is not enabled."));
1843 THREAD *thread, *top;
1846 if (CURHDR->collapsed)
1847 final = mutt_uncollapse_thread (Context, CURHDR);
1848 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1849 final = mutt_collapse_thread (Context, CURHDR);
1851 final = CURHDR->virtual;
1853 base = Context->hdrs[Context->v2r[final]];
1855 top = Context->tree;
1856 Context->collapsed = !Context->collapsed;
1857 while ((thread = top) != NULL) {
1858 while (!thread->message)
1859 thread = thread->child;
1860 h = thread->message;
1862 if (h->collapsed != Context->collapsed) {
1864 mutt_uncollapse_thread (Context, h);
1865 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1866 mutt_collapse_thread (Context, h);
1871 mutt_set_virtual (Context);
1872 for (j = 0; j < Context->vcount; j++) {
1873 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1879 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1883 /* --------------------------------------------------------------------
1884 * These functions are invoked directly from the internal-pager
1887 case OP_BOUNCE_MESSAGE:
1892 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1895 case OP_CREATE_ALIAS:
1897 mutt_create_alias (Context
1898 && Context->vcount ? CURHDR->env : NULL, NULL);
1899 MAYBE_REDRAW (menu->redraw);
1900 menu->redraw |= REDRAW_CURRENT;
1905 mutt_query_menu (NULL, 0);
1906 MAYBE_REDRAW (menu->redraw);
1909 case OP_PURGE_MESSAGE:
1916 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1919 mutt_tag_set_flag (M_DELETE, 1);
1920 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1921 if (option (OPTDELETEUNTAG))
1922 mutt_tag_set_flag (M_TAG, 0);
1923 menu->redraw = REDRAW_INDEX;
1926 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1927 mutt_set_flag (Context, CURHDR, M_PURGED,
1928 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1929 if (option (OPTDELETEUNTAG))
1930 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1931 if (option (OPTRESOLVE)) {
1932 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1933 menu->current = menu->oldcurrent;
1934 menu->redraw = REDRAW_CURRENT;
1936 else if (menu->menu == MENU_PAGER) {
1937 op = OP_DISPLAY_MESSAGE;
1941 menu->redraw |= REDRAW_MOTION_RESYNCH;
1944 menu->redraw = REDRAW_CURRENT;
1946 menu->redraw |= REDRAW_STATUS;
1949 case OP_DELETE_THREAD:
1950 case OP_DELETE_SUBTHREAD:
1956 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1958 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1959 op == OP_DELETE_THREAD ? 0 : 1);
1962 if (option (OPTDELETEUNTAG))
1963 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1964 op == OP_DELETE_THREAD ? 0 : 1);
1965 if (option (OPTRESOLVE))
1966 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1967 menu->current = menu->oldcurrent;
1968 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1974 if (Context && Context->magic == M_NNTP) {
1975 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1976 ((NNTP_DATA *) Context->data)->group))
1977 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1982 case OP_DISPLAY_ADDRESS:
1986 mutt_display_address (CURHDR->env);
1989 case OP_ENTER_COMMAND:
1991 CurrentMenu = MENU_MAIN;
1992 mutt_enter_command ();
1993 mutt_check_rescore (Context);
1994 if (option (OPTFORCEREDRAWINDEX))
1995 menu->redraw = REDRAW_FULL;
1996 unset_option (OPTFORCEREDRAWINDEX);
1997 unset_option (OPTFORCEREDRAWPAGER);
2000 case OP_EDIT_MESSAGE:
2007 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
2009 if (option (OPTPGPAUTODEC)
2010 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2011 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2012 mutt_edit_message (Context, tag ? NULL : CURHDR);
2013 menu->redraw = REDRAW_FULL;
2017 case OP_FORWARD_MESSAGE:
2023 if (option (OPTPGPAUTODEC) &&
2024 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2025 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2026 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2027 menu->redraw = REDRAW_FULL;
2031 case OP_FORGET_PASSPHRASE:
2032 crypt_forget_passphrase ();
2035 case OP_GROUP_REPLY:
2041 if (option (OPTPGPAUTODEC) &&
2042 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2043 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2045 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2046 tag ? NULL : CURHDR);
2047 menu->redraw = REDRAW_FULL;
2056 if (option (OPTPGPAUTODEC) &&
2057 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2058 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2060 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2061 tag ? NULL : CURHDR);
2062 menu->redraw = REDRAW_FULL;
2068 ci_send_message (0, NULL, NULL, Context, NULL);
2069 menu->redraw = REDRAW_FULL;
2073 if (!(WithCrypto & APPLICATION_PGP))
2076 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2077 menu->redraw = REDRAW_FULL;
2081 case OP_EXTRACT_KEYS:
2086 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2087 menu->redraw = REDRAW_FULL;
2091 case OP_CHECK_TRADITIONAL:
2092 if (!(WithCrypto & APPLICATION_PGP))
2096 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2097 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2099 if (menu->menu == MENU_PAGER) {
2100 op = OP_DISPLAY_MESSAGE;
2109 mutt_pipe_message (tag ? NULL : CURHDR);
2111 /* in an IMAP folder index with imap_peek=no, piping could change
2112 * * new or old messages status to read. Redraw what's needed.
2114 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2115 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2118 MAYBE_REDRAW (menu->redraw);
2125 mutt_print_message (tag ? NULL : CURHDR);
2127 /* in an IMAP folder index with imap_peek=no, piping could change
2128 * * new or old messages status to read. Redraw what's needed.
2130 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2131 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2136 case OP_MAIN_READ_THREAD:
2137 case OP_MAIN_READ_SUBTHREAD:
2143 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2145 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2146 op == OP_MAIN_READ_THREAD ? 0 : 1);
2149 if (option (OPTRESOLVE)) {
2150 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2151 mutt_next_thread (CURHDR) :
2152 mutt_next_subthread (CURHDR))) == -1)
2153 menu->current = menu->oldcurrent;
2155 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2159 case OP_RECALL_MESSAGE:
2162 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2163 menu->redraw = REDRAW_FULL;
2173 for (j = 0; j < Context->vcount; j++) {
2174 if (Context->hdrs[Context->v2r[j]]->tagged)
2175 mutt_resend_message (NULL, Context,
2176 Context->hdrs[Context->v2r[j]]);
2180 mutt_resend_message (NULL, Context, CURHDR);
2182 menu->redraw = REDRAW_FULL;
2188 case OP_FORWARD_TO_GROUP:
2191 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2192 Context && Context->msgcount == 0) {
2193 mutt_error (_("There are no messages."));
2196 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2197 str_casecmp (CURHDR->env->followup_to, "poster") ||
2198 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2199 _("Reply by mail as poster prefers?")) !=
2201 if (Context && Context->magic == M_NNTP
2202 && !((NNTP_DATA *) Context->data)->allowed
2203 && query_quadoption (OPT_TOMODERATED,
2205 ("Posting to this group not allowed, may be moderated. Continue?"))
2209 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2212 if (op == OP_FOLLOWUP)
2213 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2214 tag ? NULL : CURHDR);
2216 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2217 tag ? NULL : CURHDR);
2219 menu->redraw = REDRAW_FULL;
2230 if (option (OPTPGPAUTODEC) &&
2231 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2232 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2234 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2235 menu->redraw = REDRAW_FULL;
2238 case OP_SHELL_ESCAPE:
2240 mutt_shell_escape ();
2241 MAYBE_REDRAW (menu->redraw);
2245 case OP_TAG_SUBTHREAD:
2249 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2250 op == OP_TAG_THREAD ? 0 : 1);
2253 if (option (OPTRESOLVE)) {
2254 menu->current = mutt_next_thread (CURHDR);
2256 if (menu->current == -1)
2257 menu->current = menu->oldcurrent;
2259 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2269 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2272 mutt_tag_set_flag (M_DELETE, 0);
2273 mutt_tag_set_flag (M_PURGED, 0);
2274 menu->redraw = REDRAW_INDEX;
2277 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2278 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2279 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2281 menu->redraw = REDRAW_MOTION_RESYNCH;
2284 menu->redraw = REDRAW_CURRENT;
2286 menu->redraw |= REDRAW_STATUS;
2289 case OP_UNDELETE_THREAD:
2290 case OP_UNDELETE_SUBTHREAD:
2296 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2298 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2299 op == OP_UNDELETE_THREAD ? 0 : 1)
2300 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2301 op == OP_UNDELETE_THREAD ? 0 : 1);
2304 if (option (OPTRESOLVE)) {
2305 if (op == OP_UNDELETE_THREAD)
2306 menu->current = mutt_next_thread (CURHDR);
2308 menu->current = mutt_next_subthread (CURHDR);
2310 if (menu->current == -1)
2311 menu->current = menu->oldcurrent;
2313 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2322 if (option (OPTFORCEBUFFYCHECK))
2325 menu->redraw = REDRAW_FULL;
2328 case OP_VIEW_ATTACHMENTS:
2331 mutt_view_attachments (CURHDR);
2332 if (CURHDR->attach_del)
2333 Context->changed = 1;
2334 menu->redraw = REDRAW_FULL;
2344 case OP_REBUILD_CACHE:
2345 mx_rebuild_cache ();
2348 case OP_SIDEBAR_SCROLL_UP:
2349 case OP_SIDEBAR_SCROLL_DOWN:
2350 case OP_SIDEBAR_NEXT:
2351 case OP_SIDEBAR_PREV:
2352 case OP_SIDEBAR_NEXT_NEW:
2353 case OP_SIDEBAR_PREV_NEW:
2354 sidebar_scroll (op, menu->menu);
2357 if (menu->menu == MENU_MAIN)
2358 km_error_key (MENU_MAIN);
2361 if (menu->menu == MENU_PAGER) {
2362 menu->menu = MENU_MAIN;
2363 menu->redraw = REDRAW_FULL;
2365 set_option (OPTWEED); /* turn header weeding back on. */
2375 /* Close all open IMAP connections */
2379 /* Close all open NNTP connections */
2387 mutt_menuDestroy (&menu);
2391 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2398 for (color = ColorIndexList; color; color = color->next)
2399 if (mutt_pattern_exec
2400 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2401 curhdr->pair = color->pair;
2404 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];