2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 #include "mutt_curses.h"
26 #include "mutt_menu.h"
39 #include "imap_private.h"
42 #include "mutt_crypt.h"
57 static const char *No_mailbox_is_open = N_("No mailbox is open.");
58 static const char *There_are_no_messages = N_("There are no messages.");
59 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
60 static const char *Function_not_permitted_in_attach_message_mode =
61 N_("Function not permitted in attach-message mode.");
62 static const char *No_visible = N_("No visible messages.");
64 #define CHECK_MSGCOUNT if (!Context) \
67 mutt_error(_(No_mailbox_is_open)); \
70 else if (!Context->msgcount) \
73 mutt_error(_(There_are_no_messages)); \
77 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
80 mutt_error(_(No_visible)); \
85 #define CHECK_READONLY if (Context->readonly) \
88 mutt_error(_(Mailbox_is_read_only)); \
93 /* the error message returned here could be better. */
94 #define CHECK_IMAP_ACL(aclbit) if (Context->magic == M_IMAP) \
95 if (mutt_bit_isset (((IMAP_DATA *)Context->data)->capabilities, ACL) \
96 && !mutt_bit_isset(((IMAP_DATA *)Context->data)->rights,aclbit)){ \
98 mutt_error ("Operation not permitted by the IMAP ACL for this mailbox"); \
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 static void set_xterm_title_bar (char *title)
119 fputs ("\033]2;", stdout);
120 fputs (title, stdout);
121 fputs ("\007", stdout);
125 static void set_xterm_icon_name (char *name)
127 fputs ("\033]1;", stdout);
128 fputs (name, stdout);
129 fputs ("\007", stdout);
133 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
136 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
137 int edgemsgno, reverse = Sort & SORT_REVERSE;
138 HEADER *h = Context->hdrs[Context->v2r[num]];
141 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
142 flag |= M_FORMAT_TREE; /* display the thread tree */
143 if (h->display_subject)
144 flag |= M_FORMAT_FORCESUBJ;
147 if (menu->top + menu->pagelen > menu->max)
148 edgemsgno = Context->v2r[menu->max - 1];
150 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
153 edgemsgno = Context->v2r[menu->top];
155 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
159 /* if no ancestor is visible on current screen, provisionally force
161 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
163 flag |= M_FORMAT_FORCESUBJ;
166 else if (tmp->message->virtual >= 0)
169 if (flag & M_FORMAT_FORCESUBJ) {
170 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
174 /* ...but if a previous sibling is available, don't force it */
175 if (reverse ? tmp->message->msgno >
176 edgemsgno : tmp->message->msgno < edgemsgno)
178 else if (tmp->message->virtual >= 0) {
179 flag &= ~M_FORMAT_FORCESUBJ;
187 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
190 int index_color (int index_no)
192 HEADER *h = Context->hdrs[Context->v2r[index_no]];
197 mutt_set_header_color (Context, h);
201 static int ci_next_undeleted (int msgno)
205 for (i = msgno + 1; i < Context->vcount; i++)
206 if (!Context->hdrs[Context->v2r[i]]->deleted)
211 static int ci_previous_undeleted (int msgno)
215 for (i = msgno - 1; i >= 0; i--)
216 if (!Context->hdrs[Context->v2r[i]]->deleted)
221 /* Return the index of the first new message, or failing that, the first
224 static int ci_first_message (void)
228 if (Context && Context->msgcount) {
229 for (i = 0; i < Context->vcount; i++) {
230 if (!Context->hdrs[Context->v2r[i]]->read &&
231 !Context->hdrs[Context->v2r[i]]->deleted) {
232 if (!Context->hdrs[Context->v2r[i]]->old)
241 /* If Sort is reverse and not threaded, the latest message is first.
242 * If Sort is threaded, the latest message is first iff exactly one
243 * of Sort and SortAux are reverse.
245 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
246 ((Sort & SORT_MASK) == SORT_THREADS &&
247 ((Sort ^ SortAux) & SORT_REVERSE)))
250 return (Context->vcount ? Context->vcount - 1 : 0);
255 /* This should be in mx.c, but it only gets used here. */
256 static int mx_toggle_write (CONTEXT * ctx)
262 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
267 if (ctx->dontwrite) {
269 mutt_message (_("Changes to folder will be written on folder exit."));
273 mutt_message (_("Changes to folder will not be written."));
279 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
280 int oldcount, int index_hint)
282 /* store pointers to the newly added messages */
283 HEADER **save_new = NULL;
286 /* take note of the current message */
288 if (menu->current < Context->vcount)
289 menu->oldcurrent = index_hint;
291 oldcount = 0; /* invalid message number! */
294 /* We are in a limited view. Check if the new message(s) satisfy
295 * the limit criteria. If they do, set their virtual msgno so that
296 * they will be visible in the limited view */
297 if (Context->pattern) {
298 #define THIS_BODY Context->hdrs[j]->content
299 if (oldcount || check == M_REOPENED) {
300 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount;
302 if (mutt_pattern_exec
303 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
305 Context->hdrs[j]->virtual = Context->vcount;
306 Context->v2r[Context->vcount] = j;
307 Context->hdrs[j]->limited = 1;
310 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
317 /* save the list of new messages */
318 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
320 (HEADER **) safe_malloc (sizeof (HEADER *) *
321 (Context->msgcount - oldcount));
322 for (j = oldcount; j < Context->msgcount; j++)
323 save_new[j - oldcount] = Context->hdrs[j];
326 /* if the mailbox was reopened, need to rethread from scratch */
327 mutt_sort_headers (Context, (check == M_REOPENED));
329 /* uncollapse threads with new mail */
330 if ((Sort & SORT_MASK) == SORT_THREADS) {
331 if (check == M_REOPENED) {
334 Context->collapsed = 0;
336 for (h = Context->tree; h; h = h->next) {
337 for (j = h; !j->message; j = j->child);
338 mutt_uncollapse_thread (Context, j->message);
340 mutt_set_virtual (Context);
343 for (j = 0; j < Context->msgcount - oldcount; j++) {
346 for (k = 0; k < Context->msgcount; k++) {
347 HEADER *h = Context->hdrs[k];
349 if (h == save_new[j] && (!Context->pattern || h->limited))
350 mutt_uncollapse_thread (Context, h);
354 mutt_set_virtual (Context);
360 /* restore the current message to the message it was pointing to */
361 for (j = 0; j < Context->vcount; j++) {
362 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
369 if (menu->current < 0)
370 menu->current = ci_first_message ();
374 static void resort_index (MUTTMENU * menu)
377 HEADER *current = CURHDR;
380 mutt_sort_headers (Context, 0);
381 /* Restore the current message */
383 for (i = 0; i < Context->vcount; i++) {
384 if (Context->hdrs[Context->v2r[i]] == current) {
390 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
391 menu->current = mutt_parent_message (Context, current);
393 if (menu->current < 0)
394 menu->current = ci_first_message ();
396 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
399 struct mapping_t IndexHelp[] = {
400 {N_("Quit"), OP_QUIT},
401 {N_("Del"), OP_DELETE},
402 {N_("Undel"), OP_UNDELETE},
403 {N_("Save"), OP_SAVE},
404 {N_("Mail"), OP_MAIL},
405 {N_("Reply"), OP_REPLY},
406 {N_("Group"), OP_GROUP_REPLY},
407 {N_("Help"), OP_HELP},
412 struct mapping_t IndexNewsHelp[] = {
413 {N_("Quit"), OP_QUIT},
414 {N_("Del"), OP_DELETE},
415 {N_("Undel"), OP_UNDELETE},
416 {N_("Save"), OP_SAVE},
417 {N_("Post"), OP_POST},
418 {N_("Followup"), OP_FOLLOWUP},
419 {N_("Catchup"), OP_CATCHUP},
420 {N_("Help"), OP_HELP},
425 /* This function handles the message index window as well as commands returned
426 * from the pager (MENU_PAGER).
428 int mutt_index_menu (void)
430 char buf[LONG_STRING], helpstr[SHORT_STRING];
433 int done = 0; /* controls when to exit the "event" loop */
435 int tag = 0; /* has the tag-prefix command been pressed? */
440 char *cp; /* temporary variable. */
441 int index_hint; /* used to restore cursor position */
442 int do_buffy_notify = 1;
443 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
444 int attach_msg = option (OPTATTACHMSG);
446 menu = mutt_new_menu ();
447 menu->menu = MENU_MAIN;
449 menu->pagelen = LINES - 3;
450 menu->make_entry = index_make_entry;
451 menu->color = index_color;
452 menu->current = ci_first_message ();
453 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
456 && (Context->magic ==
457 M_NNTP)) ? IndexNewsHelp :
462 mutt_buffy_check (1); /* force the buffy check after we enter the folder */
463 /* record folder we open to place sidebar indicator properly */
464 if (Context && Context->path)
465 set_curbuffy (Context->path);
469 tag = 0; /* clear the tag-prefix */
471 menu->max = Context ? Context->vcount : 0;
472 oldcount = Context ? Context->msgcount : 0;
474 /* check if we need to resort the index because just about
475 * any 'op' below could do mutt_enter_command(), either here or
476 * from any new menu launched, and change $sort/$sort_aux
478 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
481 if (option (OPTREDRAWTREE) && Context && Context->msgcount
482 && (Sort & SORT_MASK) == SORT_THREADS) {
483 mutt_draw_tree (Context);
484 menu->redraw |= REDRAW_STATUS;
485 unset_option (OPTREDRAWTREE);
488 if (Context && !attach_msg) {
491 /* check for new mail in the mailbox. If nonzero, then something has
492 * changed about the file (either we got new mail or the file was
493 * modified underneath us.)
497 imap_allow_reopen (Context);
500 index_hint = (Context->vcount && menu->current >= 0
501 && menu->current < Context->vcount) ? CURHDR->index : 0;
503 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
504 if (!Context->path) {
505 /* fatal error occurred */
507 menu->redraw = REDRAW_FULL;
509 set_option (OPTSEARCHINVALID);
511 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
512 update_index (menu, Context, check, oldcount, index_hint);
514 /* notify the user of new mail */
515 if (check == M_REOPENED)
517 ("Mailbox was externally modified. Flags may be wrong."));
518 else if (check == M_NEW_MAIL) {
519 /* on new mail: redraw sidebar */
520 draw_sidebar (CurrentMenu);
521 mutt_message (_("New mail in this mailbox."));
523 if (option (OPTBEEPNEW))
526 else if (check == M_FLAGS)
527 mutt_message (_("Mailbox was externally modified."));
529 /* avoid the message being overwritten by buffy */
532 menu->redraw = REDRAW_FULL;
533 menu->max = Context->vcount;
535 set_option (OPTSEARCHINVALID);
541 imap_disallow_reopen (Context);
545 /* check for new mail in the incoming folders */
547 if ((newcount = mutt_buffy_check (0)) != oldcount) {
548 menu->redraw |= REDRAW_STATUS;
549 menu->redraw |= REDRAW_SIDEBAR;
551 if (do_buffy_notify) {
552 if (mutt_buffy_notify () && option (OPTBEEPNEW))
561 if (menu->redraw & REDRAW_SIDEBAR)
562 draw_sidebar (menu->menu);
563 if (menu->redraw & REDRAW_FULL) {
564 menu_redraw_full (menu);
565 draw_sidebar (menu->menu);
569 if (menu->menu == MENU_MAIN) {
570 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
571 menu_check_recenter (menu);
573 if (menu->redraw & REDRAW_INDEX) {
574 menu_redraw_index (menu);
575 menu->redraw |= REDRAW_STATUS;
577 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
578 menu_redraw_motion (menu);
579 else if (menu->redraw & REDRAW_CURRENT)
580 menu_redraw_current (menu);
583 if (menu->redraw & REDRAW_STATUS) {
585 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
587 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
588 SETCOLOR (MT_COLOR_STATUS);
589 mutt_paddstr (COLS, buf);
590 SETCOLOR (MT_COLOR_NORMAL);
591 set_buffystats (Context);
592 menu->redraw &= ~REDRAW_STATUS;
593 if (option (OPTXTERMSETTITLES)) {
594 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
595 set_xterm_title_bar (buf);
596 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
597 set_xterm_icon_name (buf);
602 if (menu->current < menu->max)
603 menu->oldcurrent = menu->current;
605 menu->oldcurrent = -1;
607 if (option (OPTARROWCURSOR))
608 move (menu->current - menu->top + menu->offset, 2);
610 move (menu->current - menu->top + menu->offset, COLS - 1);
613 op = km_dokey (MENU_MAIN);
616 (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op));
618 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
621 mutt_resize_screen ();
622 menu->redraw = REDRAW_FULL;
623 menu->menu = MENU_MAIN;
625 menu->top = 0; /* so we scroll the right amount */
627 * force a real complete redraw. clrtobot() doesn't seem to be able
628 * to handle every case without this.
630 clearok (stdscr, TRUE);
636 continue; /* either user abort or timeout */
640 /* special handling for the tag-prefix function */
641 if (op == OP_TAG_PREFIX) {
643 mutt_error (_("No mailbox is open."));
648 if (!Context->tagged) {
649 mutt_error (_("No tagged messages."));
655 /* give visual indication that the next command is a tag- command */
656 mvaddstr (LINES - 1, 0, "tag-");
659 /* get the real command */
660 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
661 /* abort tag sequence */
662 CLEARLINE (LINES - 1);
666 else if (option (OPTAUTOTAG) && Context && Context->tagged)
669 if (op == OP_TAG_PREFIX_COND) {
671 mutt_error (_("No mailbox is open."));
676 if (!Context->tagged) {
679 while (UngetCount > 0) {
681 if (tmp.op == OP_END_COND)
684 mutt_message (_("Nothing to do."));
690 /* give visual indication that the next command is a tag- command */
691 mvaddstr (LINES - 1, 0, "tag-");
694 /* get the real command */
695 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
696 /* abort tag sequence */
697 CLEARLINE (LINES - 1);
705 if (menu->current < menu->max)
706 menu->oldcurrent = menu->current;
708 menu->oldcurrent = -1;
710 mutt_curs_set (1); /* fallback from the pager */
714 unset_option (OPTNEWS); /* for any case */
719 /* ----------------------------------------------------------------------
724 menu_bottom_page (menu);
727 menu_first_entry (menu);
730 menu_middle_page (menu);
736 menu_half_down (menu);
739 menu_next_line (menu);
742 menu_prev_line (menu);
745 menu_next_page (menu);
748 menu_prev_page (menu);
751 menu_last_entry (menu);
754 menu_top_page (menu);
757 menu_current_top (menu);
759 case OP_CURRENT_MIDDLE:
760 menu_current_middle (menu);
762 case OP_CURRENT_BOTTOM:
763 menu_current_bottom (menu);
770 if (Context->magic == M_NNTP) {
773 if (op == OP_GET_MESSAGE) {
775 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0)
780 LIST *ref = CURHDR->env->references;
783 mutt_error (_("Article has no parent reference!"));
787 strfcpy (buf, ref->data, sizeof (buf));
789 if (!Context->id_hash)
790 Context->id_hash = mutt_make_id_hash (Context);
791 if ((h = hash_find (Context->id_hash, buf))) {
792 if (h->virtual != -1) {
793 menu->current = h->virtual;
794 menu->redraw = REDRAW_MOTION_RESYNCH;
796 else if (h->collapsed) {
797 mutt_uncollapse_thread (Context, h);
798 mutt_set_virtual (Context);
799 menu->current = h->virtual;
800 menu->redraw = REDRAW_MOTION_RESYNCH;
803 mutt_error (_("Message not visible in limited view."));
806 if (nntp_check_msgid (Context, buf) == 0) {
807 h = Context->hdrs[Context->msgcount - 1];
808 mutt_sort_headers (Context, 0);
809 menu->current = h->virtual;
810 menu->redraw = REDRAW_FULL;
813 mutt_error (_("Article %s not found on server"), buf);
818 case OP_GET_CHILDREN:
819 case OP_RECONSTRUCT_THREAD:
821 if (Context->magic == M_NNTP) {
823 int old = CURHDR->index, i;
825 if (!CURHDR->env->message_id) {
826 mutt_error (_("No Message-Id. Unable to perform operation"));
831 if (!Context->id_hash)
832 Context->id_hash = mutt_make_id_hash (Context);
833 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
835 if (op == OP_RECONSTRUCT_THREAD) {
836 LIST *ref = CURHDR->env->references;
839 nntp_check_msgid (Context, ref->data);
840 /* the last msgid in References is the root message */
842 strfcpy (buf, ref->data, sizeof (buf));
846 mutt_message (_("Check for children of message..."));
848 if (nntp_check_children (Context, buf) == 0) {
849 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
850 h = hash_find (Context->id_hash, buf);
851 /* if the root message was retrieved, move to it */
853 menu->current = h->virtual;
854 else /* try to restore old position */
855 for (i = 0; i < Context->msgcount; i++)
856 if (Context->hdrs[i]->index == old) {
857 menu->current = Context->hdrs[i]->virtual;
858 /* As an added courtesy, recenter the menu
859 * with the current entry at the middle of the screen */
860 menu_check_recenter (menu);
861 menu_current_middle (menu);
864 menu->redraw = REDRAW_FULL;
874 if (isdigit (LastKey))
875 mutt_ungetch (LastKey, 0);
877 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
881 if (!isdigit ((unsigned char) buf[0])) {
882 mutt_error (_("Argument must be a message number."));
888 if (i > 0 && i <= Context->msgcount) {
889 for (j = i - 1; j < Context->msgcount; j++) {
890 if (Context->hdrs[j]->virtual != -1)
893 if (j >= Context->msgcount) {
894 for (j = i - 2; j >= 0; j--) {
895 if (Context->hdrs[j]->virtual != -1)
901 menu->current = Context->hdrs[j]->virtual;
902 if (menu->menu == MENU_PAGER) {
903 op = OP_DISPLAY_MESSAGE;
907 menu->redraw = REDRAW_MOTION;
910 mutt_error (_("That message is not visible."));
913 mutt_error (_("Invalid message number."));
917 /* --------------------------------------------------------------------
918 * `index' specific commands
921 case OP_MAIN_DELETE_PATTERN:
928 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
932 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
933 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
937 case OP_MAIN_FETCH_MAIL:
941 menu->redraw = REDRAW_FULL;
947 mutt_help (MENU_MAIN);
948 menu->redraw = REDRAW_FULL;
951 case OP_MAIN_SHOW_LIMIT:
953 if (!Context->pattern)
954 mutt_message (_("No limit pattern is in effect."));
959 /* i18n: ask for a limit to apply */
960 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
961 mutt_message ("%s", buf);
969 menu->oldcurrent = (Context->vcount && menu->current >= 0
971 Context->vcount) ? CURHDR->index : -1;
972 if (op == OP_TOGGLE_READ) {
973 char buf[LONG_STRING];
975 if (!Context->pattern
976 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
977 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
978 Context->pattern ? Context->pattern : ".*");
979 set_option (OPTHIDEREAD);
982 strfcpy (buf, Context->pattern + 8, sizeof (buf));
983 if (!*buf || strncmp (buf, ".*", 2) == 0)
984 snprintf (buf, sizeof (buf), "~A");
985 unset_option (OPTHIDEREAD);
987 FREE (&Context->pattern);
988 Context->pattern = safe_strdup (buf);
990 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
991 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
993 if (menu->oldcurrent >= 0) {
994 /* try to find what used to be the current message */
996 for (i = 0; i < Context->vcount; i++)
997 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
1001 if (menu->current < 0)
1006 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1007 if ((Sort & SORT_MASK) == SORT_THREADS)
1008 mutt_draw_tree (Context);
1009 menu->redraw = REDRAW_FULL;
1021 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1024 oldcount = Context ? Context->msgcount : 0;
1027 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1030 if (check == M_NEW_MAIL || check == M_REOPENED)
1031 update_index (menu, Context, check, oldcount, index_hint);
1033 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1034 set_option (OPTSEARCHINVALID);
1041 clearok (stdscr, TRUE);
1042 menu->redraw = REDRAW_FULL;
1046 case OP_SEARCH_REVERSE:
1047 case OP_SEARCH_NEXT:
1048 case OP_SEARCH_OPPOSITE:
1052 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1053 menu->current = menu->oldcurrent;
1055 menu->redraw = REDRAW_MOTION;
1059 case OP_SORT_REVERSE:
1061 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1062 if (Context && Context->msgcount) {
1063 resort_index (menu);
1064 set_option (OPTSEARCHINVALID);
1073 if (tag && !option (OPTAUTOTAG)) {
1074 for (j = 0; j < Context->vcount; j++)
1075 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1076 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1079 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1080 Context->last_tag = CURHDR->tagged ? CURHDR :
1081 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1082 ? NULL : Context->last_tag);
1083 menu->redraw = REDRAW_STATUS;
1084 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1086 menu->redraw |= REDRAW_MOTION_RESYNCH;
1089 menu->redraw |= REDRAW_CURRENT;
1093 case OP_MAIN_TAG_PATTERN:
1097 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1098 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1101 case OP_MAIN_UNDELETE_PATTERN:
1108 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1111 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1113 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1116 case OP_MAIN_UNTAG_PATTERN:
1120 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1121 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1124 /* --------------------------------------------------------------------
1125 * The following operations can be performed inside of the pager.
1129 case OP_MAIN_IMAP_FETCH:
1130 if (Context->magic == M_IMAP)
1131 imap_check_mailbox (Context, &index_hint, 1);
1135 case OP_MAIN_SYNC_FOLDER:
1137 if (Context && !Context->msgcount)
1144 int oldvcount = Context->vcount;
1145 int oldcount = Context->msgcount;
1149 /* calculate the number of messages _above_ the cursor,
1150 * so we can keep the cursor on the current message
1152 for (j = 0; j <= menu->current; j++) {
1153 if (Context->hdrs[Context->v2r[j]]->deleted)
1157 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1158 if (Context->vcount != oldvcount)
1159 menu->current -= dcount;
1160 set_option (OPTSEARCHINVALID);
1162 else if (check == M_NEW_MAIL || check == M_REOPENED)
1163 update_index (menu, Context, check, oldcount, index_hint);
1166 * do a sanity check even if mx_sync_mailbox failed.
1169 if (menu->current < 0 || menu->current >= Context->vcount)
1170 menu->current = ci_first_message ();
1173 /* check for a fatal error, or all messages deleted */
1177 /* if we were in the pager, redisplay the message */
1178 if (menu->menu == MENU_PAGER) {
1179 op = OP_DISPLAY_MESSAGE;
1183 menu->redraw = REDRAW_FULL;
1186 case OP_SIDEBAR_OPEN:
1187 case OP_MAIN_CHANGE_FOLDER:
1188 case OP_MAIN_CHANGE_FOLDER_READONLY:
1190 case OP_MAIN_CHANGE_GROUP:
1191 case OP_MAIN_CHANGE_GROUP_READONLY:
1193 if (attach_msg || option (OPTREADONLY) ||
1195 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1197 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1203 cp = _("Open mailbox in read-only mode");
1205 cp = _("Open mailbox");
1209 unset_option (OPTNEWS);
1210 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1211 set_option (OPTNEWS);
1212 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1215 cp = _("Open newsgroup in read-only mode");
1217 cp = _("Open newsgroup");
1223 if (Context && Context->path)
1224 strncpy (buf, Context->path, sizeof (buf));
1225 mutt_buffy (buf, sizeof (buf));
1228 if (op == OP_SIDEBAR_OPEN) {
1231 strncpy (buf, CurBuffy->path, sizeof (buf));
1233 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1237 CLEARLINE (LINES - 1);
1242 if (option (OPTNEWS)) {
1243 unset_option (OPTNEWS);
1244 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1248 mutt_expand_path (buf, sizeof (buf));
1250 if (mx_get_magic (buf) <= 0) {
1251 mutt_error (_("%s is not a mailbox."), buf);
1254 mutt_str_replace (&CurrentFolder, buf);
1259 #ifdef USE_COMPRESSED
1260 if (Context->compressinfo && Context->realpath)
1261 mutt_str_replace (&LastFolder, Context->realpath);
1265 mutt_str_replace (&LastFolder, Context->path);
1266 oldcount = Context ? Context->msgcount : 0;
1268 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1269 if (check == M_NEW_MAIL || check == M_REOPENED)
1270 update_index (menu, Context, check, oldcount, index_hint);
1272 set_option (OPTSEARCHINVALID);
1273 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1281 /* Set CurrentMenu to MENU_MAIN before executing any folder
1282 * hooks so that all the index menu functions are available to
1286 CurrentMenu = MENU_MAIN;
1287 mutt_folder_hook (buf);
1289 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1290 menu->current = ci_first_message ();
1296 /* mutt_buffy_check() must be done with mail-reader mode! */
1297 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1299 && (Context->magic ==
1300 M_NNTP)) ? IndexNewsHelp :
1303 mutt_clear_error ();
1304 mutt_buffy_check (1); /* force the buffy check after we have changed
1306 menu->redraw = REDRAW_FULL;
1307 set_option (OPTSEARCHINVALID);
1310 case OP_DISPLAY_MESSAGE:
1311 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1316 * toggle the weeding of headers so that a user can press the key
1317 * again while reading the message.
1319 if (op == OP_DISPLAY_HEADERS)
1320 toggle_option (OPTWEED);
1322 unset_option (OPTNEEDRESORT);
1324 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1325 mutt_uncollapse_thread (Context, CURHDR);
1326 mutt_set_virtual (Context);
1327 if (option (OPTUNCOLLAPSEJUMP))
1328 menu->current = mutt_thread_next_unread (Context, CURHDR);
1331 if ((op = mutt_display_message (CURHDR)) == -1) {
1332 unset_option (OPTNEEDRESORT);
1336 menu->menu = MENU_PAGER;
1337 menu->oldcurrent = menu->current;
1343 if (menu->menu == MENU_MAIN && attach_msg) {
1348 if ((menu->menu == MENU_MAIN)
1349 && (query_quadoption (OPT_QUIT,
1350 _("Exit Mutt-ng without saving?")) == M_YES))
1353 mx_fastclose_mailbox (Context);
1365 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1366 /* if we were in the pager, redisplay the message */
1367 if (menu->menu == MENU_PAGER) {
1368 op = OP_DISPLAY_MESSAGE;
1372 menu->redraw = REDRAW_CURRENT;
1375 case OP_MAIN_BREAK_THREAD:
1381 if ((Sort & SORT_MASK) != SORT_THREADS)
1382 mutt_error (_("Threading is not enabled."));
1386 HEADER *oldcur = CURHDR;
1388 mutt_break_thread (CURHDR);
1389 mutt_sort_headers (Context, 1);
1390 menu->current = oldcur->virtual;
1393 Context->changed = 1;
1394 mutt_message _("Thread broken");
1396 if (menu->menu == MENU_PAGER) {
1397 op = OP_DISPLAY_MESSAGE;
1401 menu->redraw |= REDRAW_INDEX;
1405 case OP_MAIN_LINK_THREADS:
1411 if ((Sort & SORT_MASK) != SORT_THREADS)
1412 mutt_error (_("Threading is not enabled."));
1414 else if (!CURHDR->env->message_id)
1415 mutt_error (_("No Message-ID: header available to link thread"));
1417 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1418 mutt_error (_("First, please tag a message to be linked here"));
1421 HEADER *oldcur = CURHDR;
1423 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1425 mutt_sort_headers (Context, 1);
1426 menu->current = oldcur->virtual;
1428 Context->changed = 1;
1429 mutt_message _("Threads linked");
1432 mutt_error (_("No thread linked"));
1435 if (menu->menu == MENU_PAGER) {
1436 op = OP_DISPLAY_MESSAGE;
1440 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1443 case OP_MAIN_NEXT_UNDELETED:
1447 if (menu->current >= Context->vcount - 1) {
1448 if (menu->menu == MENU_MAIN)
1449 mutt_error (_("You are on the last message."));
1453 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1454 menu->current = menu->oldcurrent;
1455 if (menu->menu == MENU_MAIN)
1456 mutt_error (_("No undeleted messages."));
1458 else if (menu->menu == MENU_PAGER) {
1459 op = OP_DISPLAY_MESSAGE;
1463 menu->redraw = REDRAW_MOTION;
1470 if (menu->current >= Context->vcount - 1) {
1471 if (menu->menu == MENU_MAIN)
1472 mutt_error (_("You are on the last message."));
1477 if (menu->menu == MENU_PAGER) {
1478 op = OP_DISPLAY_MESSAGE;
1482 menu->redraw = REDRAW_MOTION;
1485 case OP_MAIN_PREV_UNDELETED:
1489 if (menu->current < 1) {
1490 mutt_error (_("You are on the first message."));
1494 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1495 menu->current = menu->oldcurrent;
1496 if (menu->menu == MENU_MAIN)
1497 mutt_error (_("No undeleted messages."));
1499 else if (menu->menu == MENU_PAGER) {
1500 op = OP_DISPLAY_MESSAGE;
1504 menu->redraw = REDRAW_MOTION;
1511 if (menu->current < 1) {
1512 if (menu->menu == MENU_MAIN)
1513 mutt_error (_("You are on the first message."));
1518 if (menu->menu == MENU_PAGER) {
1519 op = OP_DISPLAY_MESSAGE;
1523 menu->redraw = REDRAW_MOTION;
1526 case OP_DECRYPT_COPY:
1527 case OP_DECRYPT_SAVE:
1531 case OP_COPY_MESSAGE:
1533 case OP_DECODE_COPY:
1534 case OP_DECODE_SAVE:
1537 if (mutt_save_message (tag ? NULL : CURHDR,
1538 (op == OP_DECRYPT_SAVE) ||
1539 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1540 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1541 (op == OP_DECRYPT_SAVE)
1542 || (op == OP_DECRYPT_COPY)
1543 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1550 menu->redraw |= REDRAW_INDEX;
1551 else if (option (OPTRESOLVE)) {
1552 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1553 menu->current = menu->oldcurrent;
1554 menu->redraw |= REDRAW_CURRENT;
1557 menu->redraw |= REDRAW_MOTION_RESYNCH;
1560 menu->redraw |= REDRAW_CURRENT;
1564 case OP_MAIN_NEXT_NEW:
1565 case OP_MAIN_NEXT_UNREAD:
1566 case OP_MAIN_PREV_NEW:
1567 case OP_MAIN_PREV_UNREAD:
1568 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1569 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1572 int first_unread = -1;
1580 for (j = 0; j != Context->vcount; j++) {
1581 #define CURHDRi Context->hdrs[Context->v2r[i]]
1582 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1583 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1585 if (i > Context->vcount - 1) {
1586 mutt_message _("Search wrapped to top.");
1594 mutt_message _("Search wrapped to bottom.");
1596 i = Context->vcount - 1;
1600 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1601 if (UNREAD (CURHDRi) && first_unread == -1)
1603 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1606 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1607 if (first_unread == -1)
1609 if ((!CURHDRi->old) && first_new == -1)
1613 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1616 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1617 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1618 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1623 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1624 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1625 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1627 menu->current = first_new;
1628 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1629 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1630 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1631 && first_unread != -1)
1632 menu->current = first_unread;
1634 if (menu->current == -1) {
1635 menu->current = menu->oldcurrent;
1636 mutt_error ("%s%s.",
1637 (op == OP_MAIN_NEXT_NEW
1639 OP_MAIN_PREV_NEW) ? _("No new messages") :
1640 _("No unread messages"),
1641 Context->pattern ? _(" in this limited view") : "");
1643 else if (menu->menu == MENU_PAGER) {
1644 op = OP_DISPLAY_MESSAGE;
1648 menu->redraw = REDRAW_MOTION;
1651 case OP_FLAG_MESSAGE:
1658 if (Context->magic == M_POP) {
1660 mutt_error (_("Can't change 'important' flag on POP server."));
1667 CHECK_IMAP_ACL (IMAP_ACL_WRITE);
1671 if (Context->magic == M_NNTP) {
1673 mutt_error (_("Can't change 'important' flag on NNTP server."));
1680 for (j = 0; j < Context->vcount; j++) {
1681 if (Context->hdrs[Context->v2r[j]]->tagged)
1682 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1683 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1686 menu->redraw |= REDRAW_INDEX;
1689 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1690 if (option (OPTRESOLVE)) {
1691 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1692 menu->current = menu->oldcurrent;
1693 menu->redraw = REDRAW_CURRENT;
1696 menu->redraw = REDRAW_MOTION_RESYNCH;
1699 menu->redraw = REDRAW_CURRENT;
1701 menu->redraw |= REDRAW_STATUS;
1711 CHECK_IMAP_ACL (IMAP_ACL_SEEN);
1715 for (j = 0; j < Context->vcount; j++) {
1716 if (Context->hdrs[Context->v2r[j]]->tagged) {
1717 if (Context->hdrs[Context->v2r[j]]->read ||
1718 Context->hdrs[Context->v2r[j]]->old)
1719 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1722 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1726 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1729 if (CURHDR->read || CURHDR->old)
1730 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1732 mutt_set_flag (Context, CURHDR, M_READ, 1);
1734 if (option (OPTRESOLVE)) {
1735 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1736 menu->current = menu->oldcurrent;
1737 menu->redraw = REDRAW_CURRENT;
1740 menu->redraw = REDRAW_MOTION_RESYNCH;
1743 menu->redraw = REDRAW_CURRENT;
1744 menu->redraw |= REDRAW_STATUS;
1748 case OP_TOGGLE_WRITE:
1751 if (mx_toggle_write (Context) == 0)
1752 menu->redraw |= REDRAW_STATUS;
1755 case OP_MAIN_NEXT_THREAD:
1756 case OP_MAIN_NEXT_SUBTHREAD:
1757 case OP_MAIN_PREV_THREAD:
1758 case OP_MAIN_PREV_SUBTHREAD:
1763 case OP_MAIN_NEXT_THREAD:
1764 menu->current = mutt_next_thread (CURHDR);
1767 case OP_MAIN_NEXT_SUBTHREAD:
1768 menu->current = mutt_next_subthread (CURHDR);
1771 case OP_MAIN_PREV_THREAD:
1772 menu->current = mutt_previous_thread (CURHDR);
1775 case OP_MAIN_PREV_SUBTHREAD:
1776 menu->current = mutt_previous_subthread (CURHDR);
1780 if (menu->current < 0) {
1781 menu->current = menu->oldcurrent;
1782 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1783 mutt_error (_("No more threads."));
1786 mutt_error (_("You are on the first thread."));
1788 else if (menu->menu == MENU_PAGER) {
1789 op = OP_DISPLAY_MESSAGE;
1793 menu->redraw = REDRAW_MOTION;
1796 case OP_MAIN_PARENT_MESSAGE:
1801 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1802 menu->current = menu->oldcurrent;
1804 else if (menu->menu == MENU_PAGER) {
1805 op = OP_DISPLAY_MESSAGE;
1809 menu->redraw = REDRAW_MOTION;
1812 case OP_MAIN_SET_FLAG:
1813 case OP_MAIN_CLEAR_FLAG:
1820 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1823 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1825 menu->redraw = REDRAW_STATUS;
1827 menu->redraw |= REDRAW_INDEX;
1828 else if (option (OPTRESOLVE)) {
1829 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1830 menu->current = menu->oldcurrent;
1831 menu->redraw |= REDRAW_CURRENT;
1834 menu->redraw |= REDRAW_MOTION_RESYNCH;
1837 menu->redraw |= REDRAW_CURRENT;
1841 case OP_MAIN_COLLAPSE_THREAD:
1845 if ((Sort & SORT_MASK) != SORT_THREADS) {
1846 mutt_error (_("Threading is not enabled."));
1851 if (CURHDR->collapsed) {
1852 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1853 mutt_set_virtual (Context);
1854 if (option (OPTUNCOLLAPSEJUMP))
1855 menu->current = mutt_thread_next_unread (Context, CURHDR);
1857 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1858 menu->current = mutt_collapse_thread (Context, CURHDR);
1859 mutt_set_virtual (Context);
1862 mutt_error (_("Thread contains unread messages."));
1867 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1871 case OP_MAIN_COLLAPSE_ALL:
1875 if ((Sort & SORT_MASK) != SORT_THREADS) {
1876 mutt_error (_("Threading is not enabled."));
1883 THREAD *thread, *top;
1886 if (CURHDR->collapsed)
1887 final = mutt_uncollapse_thread (Context, CURHDR);
1888 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1889 final = mutt_collapse_thread (Context, CURHDR);
1891 final = CURHDR->virtual;
1893 base = Context->hdrs[Context->v2r[final]];
1895 top = Context->tree;
1896 Context->collapsed = !Context->collapsed;
1897 while ((thread = top) != NULL) {
1898 while (!thread->message)
1899 thread = thread->child;
1900 h = thread->message;
1902 if (h->collapsed != Context->collapsed) {
1904 mutt_uncollapse_thread (Context, h);
1905 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1906 mutt_collapse_thread (Context, h);
1911 mutt_set_virtual (Context);
1912 for (j = 0; j < Context->vcount; j++) {
1913 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1919 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1923 /* --------------------------------------------------------------------
1924 * These functions are invoked directly from the internal-pager
1927 case OP_BOUNCE_MESSAGE:
1932 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1935 case OP_CREATE_ALIAS:
1937 mutt_create_alias (Context
1938 && Context->vcount ? CURHDR->env : NULL, NULL);
1939 MAYBE_REDRAW (menu->redraw);
1940 menu->redraw |= REDRAW_CURRENT;
1945 mutt_query_menu (NULL, 0);
1946 MAYBE_REDRAW (menu->redraw);
1949 case OP_PURGE_MESSAGE:
1957 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1961 mutt_tag_set_flag (M_DELETE, 1);
1962 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1963 if (option (OPTDELETEUNTAG))
1964 mutt_tag_set_flag (M_TAG, 0);
1965 menu->redraw = REDRAW_INDEX;
1968 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1969 mutt_set_flag (Context, CURHDR, M_PURGED,
1970 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1971 if (option (OPTDELETEUNTAG))
1972 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1973 if (option (OPTRESOLVE)) {
1974 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1975 menu->current = menu->oldcurrent;
1976 menu->redraw = REDRAW_CURRENT;
1978 else if (menu->menu == MENU_PAGER) {
1979 op = OP_DISPLAY_MESSAGE;
1983 menu->redraw |= REDRAW_MOTION_RESYNCH;
1986 menu->redraw = REDRAW_CURRENT;
1988 menu->redraw |= REDRAW_STATUS;
1991 case OP_DELETE_THREAD:
1992 case OP_DELETE_SUBTHREAD:
1999 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2002 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
2003 op == OP_DELETE_THREAD ? 0 : 1);
2006 if (option (OPTDELETEUNTAG))
2007 mutt_thread_set_flag (CURHDR, M_TAG, 0,
2008 op == OP_DELETE_THREAD ? 0 : 1);
2009 if (option (OPTRESOLVE))
2010 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
2011 menu->current = menu->oldcurrent;
2012 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2018 if (Context && Context->magic == M_NNTP) {
2019 if (mutt_newsgroup_catchup (CurrentNewsSrv,
2020 ((NNTP_DATA *) Context->data)->group))
2021 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2026 case OP_DISPLAY_ADDRESS:
2030 mutt_display_address (CURHDR->env);
2033 case OP_ENTER_COMMAND:
2035 CurrentMenu = MENU_MAIN;
2036 mutt_enter_command ();
2037 mutt_check_rescore (Context);
2038 if (option (OPTFORCEREDRAWINDEX))
2039 menu->redraw = REDRAW_FULL;
2040 unset_option (OPTFORCEREDRAWINDEX);
2041 unset_option (OPTFORCEREDRAWPAGER);
2044 case OP_EDIT_MESSAGE:
2052 if (Context->magic == M_POP) {
2054 mutt_error (_("Can't edit message on POP server."));
2061 CHECK_IMAP_ACL (IMAP_ACL_INSERT);
2065 if (Context->magic == M_NNTP) {
2067 mutt_error (_("Can't edit message on newsserver."));
2073 if (option (OPTPGPAUTODEC)
2074 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2075 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2076 mutt_edit_message (Context, tag ? NULL : CURHDR);
2077 menu->redraw = REDRAW_FULL;
2081 case OP_FORWARD_MESSAGE:
2086 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2087 menu->redraw = REDRAW_FULL;
2091 case OP_FORGET_PASSPHRASE:
2092 crypt_forget_passphrase ();
2095 case OP_GROUP_REPLY:
2100 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2101 tag ? NULL : CURHDR);
2102 menu->redraw = REDRAW_FULL;
2110 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2111 tag ? NULL : CURHDR);
2112 menu->redraw = REDRAW_FULL;
2118 ci_send_message (0, NULL, NULL, Context, NULL);
2119 menu->redraw = REDRAW_FULL;
2123 if (!(WithCrypto & APPLICATION_PGP))
2126 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2127 menu->redraw = REDRAW_FULL;
2131 case OP_EXTRACT_KEYS:
2136 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2137 menu->redraw = REDRAW_FULL;
2141 case OP_CHECK_TRADITIONAL:
2142 if (!(WithCrypto & APPLICATION_PGP))
2146 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2147 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2149 if (menu->menu == MENU_PAGER) {
2150 op = OP_DISPLAY_MESSAGE;
2159 mutt_pipe_message (tag ? NULL : CURHDR);
2160 MAYBE_REDRAW (menu->redraw);
2167 mutt_print_message (tag ? NULL : CURHDR);
2170 case OP_MAIN_READ_THREAD:
2171 case OP_MAIN_READ_SUBTHREAD:
2178 CHECK_IMAP_ACL (IMAP_ACL_SEEN);
2181 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2182 op == OP_MAIN_READ_THREAD ? 0 : 1);
2185 if (option (OPTRESOLVE)) {
2186 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2187 mutt_next_thread (CURHDR) :
2188 mutt_next_subthread (CURHDR))) == -1)
2189 menu->current = menu->oldcurrent;
2191 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2195 case OP_RECALL_MESSAGE:
2198 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2199 menu->redraw = REDRAW_FULL;
2209 for (j = 0; j < Context->vcount; j++) {
2210 if (Context->hdrs[Context->v2r[j]]->tagged)
2211 mutt_resend_message (NULL, Context,
2212 Context->hdrs[Context->v2r[j]]);
2216 mutt_resend_message (NULL, Context, CURHDR);
2218 menu->redraw = REDRAW_FULL;
2224 case OP_FORWARD_TO_GROUP:
2227 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2228 Context && Context->msgcount == 0) {
2229 mutt_error (_("There are no messages."));
2232 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2233 mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2234 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2235 _("Reply by mail as poster prefers?")) !=
2237 if (Context && Context->magic == M_NNTP
2238 && !((NNTP_DATA *) Context->data)->allowed
2239 && query_quadoption (OPT_TOMODERATED,
2241 ("Posting to this group not allowed, may be moderated. Continue?"))
2245 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2248 if (op == OP_FOLLOWUP)
2249 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2250 tag ? NULL : CURHDR);
2252 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2253 tag ? NULL : CURHDR);
2255 menu->redraw = REDRAW_FULL;
2265 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2266 menu->redraw = REDRAW_FULL;
2269 case OP_SHELL_ESCAPE:
2271 mutt_shell_escape ();
2272 MAYBE_REDRAW (menu->redraw);
2276 case OP_TAG_SUBTHREAD:
2280 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2281 op == OP_TAG_THREAD ? 0 : 1);
2284 if (option (OPTRESOLVE)) {
2285 menu->current = mutt_next_thread (CURHDR);
2287 if (menu->current == -1)
2288 menu->current = menu->oldcurrent;
2290 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2301 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2305 mutt_tag_set_flag (M_DELETE, 0);
2306 mutt_tag_set_flag (M_PURGED, 0);
2307 menu->redraw = REDRAW_INDEX;
2310 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2311 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2312 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2314 menu->redraw = REDRAW_MOTION_RESYNCH;
2317 menu->redraw = REDRAW_CURRENT;
2319 menu->redraw |= REDRAW_STATUS;
2322 case OP_UNDELETE_THREAD:
2323 case OP_UNDELETE_SUBTHREAD:
2330 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2333 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2334 op == OP_UNDELETE_THREAD ? 0 : 1)
2335 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2336 op == OP_UNDELETE_THREAD ? 0 : 1);
2339 if (option (OPTRESOLVE)) {
2340 if (op == OP_UNDELETE_THREAD)
2341 menu->current = mutt_next_thread (CURHDR);
2343 menu->current = mutt_next_subthread (CURHDR);
2345 if (menu->current == -1)
2346 menu->current = menu->oldcurrent;
2348 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2358 menu->redraw = REDRAW_FULL;
2361 case OP_VIEW_ATTACHMENTS:
2364 mutt_view_attachments (CURHDR);
2365 if (CURHDR->attach_del)
2366 Context->changed = 1;
2367 menu->redraw = REDRAW_FULL;
2377 case OP_SIDEBAR_SCROLL_UP:
2378 case OP_SIDEBAR_SCROLL_DOWN:
2379 case OP_SIDEBAR_NEXT:
2380 case OP_SIDEBAR_PREV:
2381 case OP_SIDEBAR_NEXT_NEW:
2382 case OP_SIDEBAR_PREV_NEW:
2383 scroll_sidebar (op, menu->menu);
2386 if (menu->menu == MENU_MAIN)
2387 km_error_key (MENU_MAIN);
2390 if (menu->menu == MENU_PAGER) {
2391 menu->menu = MENU_MAIN;
2392 menu->redraw = REDRAW_FULL;
2394 set_option (OPTWEED); /* turn header weeding back on. */
2403 /* Close all open IMAP connections */
2408 /* Close all open NNTP connections */
2413 mutt_menuDestroy (&menu);
2417 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2424 for (color = ColorIndexList; color; color = color->next)
2425 if (mutt_pattern_exec
2426 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2427 curhdr->pair = color->pair;
2430 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];