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"
32 #include "imap_private.h"
35 #include "mutt_crypt.h"
53 static const char *No_mailbox_is_open = N_("No mailbox is open.");
54 static const char *There_are_no_messages = N_("There are no messages.");
55 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
56 static const char *Function_not_permitted_in_attach_message_mode =
57 N_("Function not permitted in attach-message mode.");
58 static const char *No_visible = N_("No visible messages.");
60 #define CHECK_MSGCOUNT if (!Context) \
63 mutt_error(_(No_mailbox_is_open)); \
66 else if (!Context->msgcount) \
69 mutt_error(_(There_are_no_messages)); \
73 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
76 mutt_error(_(No_visible)); \
81 #define CHECK_READONLY if (Context->readonly) \
84 mutt_error(_(Mailbox_is_read_only)); \
89 /* the error message returned here could be better. */
90 #define CHECK_IMAP_ACL(aclbit) if (Context->magic == M_IMAP) \
91 if (mutt_bit_isset (((IMAP_DATA *)Context->data)->capabilities, ACL) \
92 && !mutt_bit_isset(((IMAP_DATA *)Context->data)->rights,aclbit)){ \
94 mutt_error ("Operation not permitted by the IMAP ACL for this mailbox"); \
99 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
102 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
106 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
107 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
108 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
110 extern const char *ReleaseDate;
111 extern size_t UngetCount;
113 static void set_xterm_title_bar (char *title)
115 fputs ("\033]2;", stdout);
116 fputs (title, stdout);
117 fputs ("\007", stdout);
121 static void set_xterm_icon_name (char *name)
123 fputs ("\033]1;", stdout);
124 fputs (name, stdout);
125 fputs ("\007", stdout);
129 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
132 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
133 int edgemsgno, reverse = Sort & SORT_REVERSE;
134 HEADER *h = Context->hdrs[Context->v2r[num]];
137 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
138 flag |= M_FORMAT_TREE; /* display the thread tree */
139 if (h->display_subject)
140 flag |= M_FORMAT_FORCESUBJ;
143 if (menu->top + menu->pagelen > menu->max)
144 edgemsgno = Context->v2r[menu->max - 1];
146 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
149 edgemsgno = Context->v2r[menu->top];
151 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
155 /* if no ancestor is visible on current screen, provisionally force
157 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
159 flag |= M_FORMAT_FORCESUBJ;
162 else if (tmp->message->virtual >= 0)
165 if (flag & M_FORMAT_FORCESUBJ) {
166 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
170 /* ...but if a previous sibling is available, don't force it */
171 if (reverse ? tmp->message->msgno >
172 edgemsgno : tmp->message->msgno < edgemsgno)
174 else if (tmp->message->virtual >= 0) {
175 flag &= ~M_FORMAT_FORCESUBJ;
183 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
186 int index_color (int index_no)
188 HEADER *h = Context->hdrs[Context->v2r[index_no]];
193 mutt_set_header_color (Context, h);
197 static int ci_next_undeleted (int msgno)
201 for (i = msgno + 1; i < Context->vcount; i++)
202 if (!Context->hdrs[Context->v2r[i]]->deleted)
207 static int ci_previous_undeleted (int msgno)
211 for (i = msgno - 1; i >= 0; i--)
212 if (!Context->hdrs[Context->v2r[i]]->deleted)
217 /* Return the index of the first new message, or failing that, the first
220 static int ci_first_message (void)
224 if (Context && Context->msgcount) {
225 for (i = 0; i < Context->vcount; i++) {
226 if (!Context->hdrs[Context->v2r[i]]->read &&
227 !Context->hdrs[Context->v2r[i]]->deleted) {
228 if (!Context->hdrs[Context->v2r[i]]->old)
237 /* If Sort is reverse and not threaded, the latest message is first.
238 * If Sort is threaded, the latest message is first iff exactly one
239 * of Sort and SortAux are reverse.
241 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
242 ((Sort & SORT_MASK) == SORT_THREADS &&
243 ((Sort ^ SortAux) & SORT_REVERSE)))
246 return (Context->vcount ? Context->vcount - 1 : 0);
251 /* This should be in mx.c, but it only gets used here. */
252 static int mx_toggle_write (CONTEXT * ctx)
258 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
263 if (ctx->dontwrite) {
265 mutt_message (_("Changes to folder will be written on folder exit."));
269 mutt_message (_("Changes to folder will not be written."));
275 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
276 int oldcount, int index_hint)
278 /* store pointers to the newly added messages */
279 HEADER **save_new = NULL;
282 /* take note of the current message */
284 if (menu->current < Context->vcount)
285 menu->oldcurrent = index_hint;
287 oldcount = 0; /* invalid message number! */
290 /* We are in a limited view. Check if the new message(s) satisfy
291 * the limit criteria. If they do, set their virtual msgno so that
292 * they will be visible in the limited view */
293 if (Context->pattern) {
294 #define THIS_BODY Context->hdrs[j]->content
295 if (oldcount || check == M_REOPENED) {
296 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount;
298 if (mutt_pattern_exec
299 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
301 Context->hdrs[j]->virtual = Context->vcount;
302 Context->v2r[Context->vcount] = j;
303 Context->hdrs[j]->limited = 1;
306 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
313 /* save the list of new messages */
314 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
316 (HEADER **) safe_malloc (sizeof (HEADER *) *
317 (Context->msgcount - oldcount));
318 for (j = oldcount; j < Context->msgcount; j++)
319 save_new[j - oldcount] = Context->hdrs[j];
322 /* if the mailbox was reopened, need to rethread from scratch */
323 mutt_sort_headers (Context, (check == M_REOPENED));
325 /* uncollapse threads with new mail */
326 if ((Sort & SORT_MASK) == SORT_THREADS) {
327 if (check == M_REOPENED) {
330 Context->collapsed = 0;
332 for (h = Context->tree; h; h = h->next) {
333 for (j = h; !j->message; j = j->child);
334 mutt_uncollapse_thread (Context, j->message);
336 mutt_set_virtual (Context);
339 for (j = 0; j < Context->msgcount - oldcount; j++) {
342 for (k = 0; k < Context->msgcount; k++) {
343 HEADER *h = Context->hdrs[k];
345 if (h == save_new[j] && (!Context->pattern || h->limited))
346 mutt_uncollapse_thread (Context, h);
350 mutt_set_virtual (Context);
356 /* restore the current message to the message it was pointing to */
357 for (j = 0; j < Context->vcount; j++) {
358 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
365 if (menu->current < 0)
366 menu->current = ci_first_message ();
370 static void resort_index (MUTTMENU * menu)
373 HEADER *current = CURHDR;
376 mutt_sort_headers (Context, 0);
377 /* Restore the current message */
379 for (i = 0; i < Context->vcount; i++) {
380 if (Context->hdrs[Context->v2r[i]] == current) {
386 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
387 menu->current = mutt_parent_message (Context, current);
389 if (menu->current < 0)
390 menu->current = ci_first_message ();
392 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
395 struct mapping_t IndexHelp[] = {
396 {N_("Quit"), OP_QUIT},
397 {N_("Del"), OP_DELETE},
398 {N_("Undel"), OP_UNDELETE},
399 {N_("Save"), OP_SAVE},
400 {N_("Mail"), OP_MAIL},
401 {N_("Reply"), OP_REPLY},
402 {N_("Group"), OP_GROUP_REPLY},
403 {N_("Help"), OP_HELP},
408 struct mapping_t IndexNewsHelp[] = {
409 {N_("Quit"), OP_QUIT},
410 {N_("Del"), OP_DELETE},
411 {N_("Undel"), OP_UNDELETE},
412 {N_("Save"), OP_SAVE},
413 {N_("Post"), OP_POST},
414 {N_("Followup"), OP_FOLLOWUP},
415 {N_("Catchup"), OP_CATCHUP},
416 {N_("Help"), OP_HELP},
421 /* This function handles the message index window as well as commands returned
422 * from the pager (MENU_PAGER).
424 int mutt_index_menu (void)
426 char buf[LONG_STRING], helpstr[SHORT_STRING];
429 int done = 0; /* controls when to exit the "event" loop */
431 int tag = 0; /* has the tag-prefix command been pressed? */
436 char *cp; /* temporary variable. */
437 int index_hint; /* used to restore cursor position */
438 int do_buffy_notify = 1;
439 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
440 int attach_msg = option (OPTATTACHMSG);
442 menu = mutt_new_menu ();
443 menu->menu = MENU_MAIN;
445 menu->pagelen = LINES - 3;
446 menu->make_entry = index_make_entry;
447 menu->color = index_color;
448 menu->current = ci_first_message ();
449 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
452 && (Context->magic ==
453 M_NNTP)) ? IndexNewsHelp :
458 mutt_buffy_check (1); /* force the buffy check after we enter the folder */
459 /* record folder we open to place sidebar indicator properly */
460 if (Context && Context->path)
461 sidebar_set_current (Context->path);
465 tag = 0; /* clear the tag-prefix */
467 menu->max = Context ? Context->vcount : 0;
468 oldcount = Context ? Context->msgcount : 0;
470 /* check if we need to resort the index because just about
471 * any 'op' below could do mutt_enter_command(), either here or
472 * from any new menu launched, and change $sort/$sort_aux
474 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
477 if (option (OPTREDRAWTREE) && Context && Context->msgcount
478 && (Sort & SORT_MASK) == SORT_THREADS) {
479 mutt_draw_tree (Context);
480 menu->redraw |= REDRAW_STATUS;
481 unset_option (OPTREDRAWTREE);
484 if (Context && !attach_msg) {
487 /* check for new mail in the mailbox. If nonzero, then something has
488 * changed about the file (either we got new mail or the file was
489 * modified underneath us.)
493 imap_allow_reopen (Context);
496 index_hint = (Context->vcount && menu->current >= 0
497 && menu->current < Context->vcount) ? CURHDR->index : 0;
499 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
500 if (!Context->path) {
501 /* fatal error occurred */
503 menu->redraw = REDRAW_FULL;
505 set_option (OPTSEARCHINVALID);
507 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
508 update_index (menu, Context, check, oldcount, index_hint);
510 /* notify the user of new mail */
511 if (check == M_REOPENED)
513 ("Mailbox was externally modified. Flags may be wrong."));
514 else if (check == M_NEW_MAIL) {
515 /* on new mail: redraw sidebar */
516 sidebar_draw (CurrentMenu);
517 mutt_message (_("New mail in this mailbox."));
519 if (option (OPTBEEPNEW))
522 else if (check == M_FLAGS)
523 mutt_message (_("Mailbox was externally modified."));
525 /* avoid the message being overwritten by buffy */
528 menu->redraw = REDRAW_FULL;
529 menu->max = Context->vcount;
531 set_option (OPTSEARCHINVALID);
537 imap_disallow_reopen (Context);
541 /* check for new mail in the incoming folders */
543 if ((newcount = mutt_buffy_check (0)) != oldcount) {
544 menu->redraw |= REDRAW_STATUS;
545 menu->redraw |= REDRAW_SIDEBAR;
547 if (do_buffy_notify) {
548 if (mutt_buffy_notify () && option (OPTBEEPNEW))
557 if (menu->redraw & REDRAW_SIDEBAR)
558 sidebar_draw (menu->menu);
559 if (menu->redraw & REDRAW_FULL) {
560 menu_redraw_full (menu);
561 sidebar_draw (menu->menu);
565 if (menu->menu == MENU_MAIN) {
566 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
567 menu_check_recenter (menu);
569 if (menu->redraw & REDRAW_INDEX) {
570 menu_redraw_index (menu);
571 menu->redraw |= REDRAW_STATUS;
573 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
574 menu_redraw_motion (menu);
575 else if (menu->redraw & REDRAW_CURRENT)
576 menu_redraw_current (menu);
579 if (menu->redraw & REDRAW_STATUS) {
581 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
583 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
584 SETCOLOR (MT_COLOR_STATUS);
585 mutt_paddstr (COLS, buf);
586 SETCOLOR (MT_COLOR_NORMAL);
587 sidebar_set_buffystats (Context);
588 menu->redraw &= ~REDRAW_STATUS;
589 if (option (OPTXTERMSETTITLES)) {
590 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
591 set_xterm_title_bar (buf);
592 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
593 set_xterm_icon_name (buf);
598 if (menu->current < menu->max)
599 menu->oldcurrent = menu->current;
601 menu->oldcurrent = -1;
603 if (option (OPTARROWCURSOR))
604 move (menu->current - menu->top + menu->offset, 2);
606 move (menu->current - menu->top + menu->offset, COLS - 1);
609 op = km_dokey (MENU_MAIN);
612 (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op));
614 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
617 mutt_resize_screen ();
618 menu->redraw = REDRAW_FULL;
619 menu->menu = MENU_MAIN;
621 menu->top = 0; /* so we scroll the right amount */
623 * force a real complete redraw. clrtobot() doesn't seem to be able
624 * to handle every case without this.
626 clearok (stdscr, TRUE);
632 continue; /* either user abort or timeout */
636 /* special handling for the tag-prefix function */
637 if (op == OP_TAG_PREFIX) {
639 mutt_error (_("No mailbox is open."));
644 if (!Context->tagged) {
645 mutt_error (_("No tagged messages."));
651 /* give visual indication that the next command is a tag- command */
652 mvaddstr (LINES - 1, 0, "tag-");
655 /* get the real command */
656 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
657 /* abort tag sequence */
658 CLEARLINE (LINES - 1);
662 else if (option (OPTAUTOTAG) && Context && Context->tagged)
665 if (op == OP_TAG_PREFIX_COND) {
667 mutt_error (_("No mailbox is open."));
672 if (!Context->tagged) {
675 while (UngetCount > 0) {
677 if (tmp.op == OP_END_COND)
680 mutt_message (_("Nothing to do."));
686 /* give visual indication that the next command is a tag- command */
687 mvaddstr (LINES - 1, 0, "tag-");
690 /* get the real command */
691 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
692 /* abort tag sequence */
693 CLEARLINE (LINES - 1);
701 if (menu->current < menu->max)
702 menu->oldcurrent = menu->current;
704 menu->oldcurrent = -1;
706 mutt_curs_set (1); /* fallback from the pager */
710 unset_option (OPTNEWS); /* for any case */
715 /* ----------------------------------------------------------------------
720 menu_bottom_page (menu);
723 menu_first_entry (menu);
726 menu_middle_page (menu);
732 menu_half_down (menu);
735 menu_next_line (menu);
738 menu_prev_line (menu);
741 menu_next_page (menu);
744 menu_prev_page (menu);
747 menu_last_entry (menu);
750 menu_top_page (menu);
753 menu_current_top (menu);
755 case OP_CURRENT_MIDDLE:
756 menu_current_middle (menu);
758 case OP_CURRENT_BOTTOM:
759 menu_current_bottom (menu);
766 if (Context->magic == M_NNTP) {
769 if (op == OP_GET_MESSAGE) {
771 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0)
776 LIST *ref = CURHDR->env->references;
779 mutt_error (_("Article has no parent reference!"));
783 strfcpy (buf, ref->data, sizeof (buf));
785 if (!Context->id_hash)
786 Context->id_hash = mutt_make_id_hash (Context);
787 if ((h = hash_find (Context->id_hash, buf))) {
788 if (h->virtual != -1) {
789 menu->current = h->virtual;
790 menu->redraw = REDRAW_MOTION_RESYNCH;
792 else if (h->collapsed) {
793 mutt_uncollapse_thread (Context, h);
794 mutt_set_virtual (Context);
795 menu->current = h->virtual;
796 menu->redraw = REDRAW_MOTION_RESYNCH;
799 mutt_error (_("Message not visible in limited view."));
802 if (nntp_check_msgid (Context, buf) == 0) {
803 h = Context->hdrs[Context->msgcount - 1];
804 mutt_sort_headers (Context, 0);
805 menu->current = h->virtual;
806 menu->redraw = REDRAW_FULL;
809 mutt_error (_("Article %s not found on server"), buf);
814 case OP_GET_CHILDREN:
815 case OP_RECONSTRUCT_THREAD:
817 if (Context->magic == M_NNTP) {
819 int old = CURHDR->index, i;
821 if (!CURHDR->env->message_id) {
822 mutt_error (_("No Message-Id. Unable to perform operation"));
827 if (!Context->id_hash)
828 Context->id_hash = mutt_make_id_hash (Context);
829 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
831 if (op == OP_RECONSTRUCT_THREAD) {
832 LIST *ref = CURHDR->env->references;
835 nntp_check_msgid (Context, ref->data);
836 /* the last msgid in References is the root message */
838 strfcpy (buf, ref->data, sizeof (buf));
842 mutt_message (_("Check for children of message..."));
844 if (nntp_check_children (Context, buf) == 0) {
845 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
846 h = hash_find (Context->id_hash, buf);
847 /* if the root message was retrieved, move to it */
849 menu->current = h->virtual;
850 else /* try to restore old position */
851 for (i = 0; i < Context->msgcount; i++)
852 if (Context->hdrs[i]->index == old) {
853 menu->current = Context->hdrs[i]->virtual;
854 /* As an added courtesy, recenter the menu
855 * with the current entry at the middle of the screen */
856 menu_check_recenter (menu);
857 menu_current_middle (menu);
860 menu->redraw = REDRAW_FULL;
870 if (isdigit (LastKey))
871 mutt_ungetch (LastKey, 0);
873 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
877 if (!isdigit ((unsigned char) buf[0])) {
878 mutt_error (_("Argument must be a message number."));
884 if (i > 0 && i <= Context->msgcount) {
885 for (j = i - 1; j < Context->msgcount; j++) {
886 if (Context->hdrs[j]->virtual != -1)
889 if (j >= Context->msgcount) {
890 for (j = i - 2; j >= 0; j--) {
891 if (Context->hdrs[j]->virtual != -1)
897 menu->current = Context->hdrs[j]->virtual;
898 if (menu->menu == MENU_PAGER) {
899 op = OP_DISPLAY_MESSAGE;
903 menu->redraw = REDRAW_MOTION;
906 mutt_error (_("That message is not visible."));
909 mutt_error (_("Invalid message number."));
913 /* --------------------------------------------------------------------
914 * `index' specific commands
917 case OP_MAIN_DELETE_PATTERN:
924 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
928 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
929 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
933 case OP_MAIN_FETCH_MAIL:
937 menu->redraw = REDRAW_FULL;
943 mutt_help (MENU_MAIN);
944 menu->redraw = REDRAW_FULL;
947 case OP_MAIN_SHOW_LIMIT:
949 if (!Context->pattern)
950 mutt_message (_("No limit pattern is in effect."));
955 /* i18n: ask for a limit to apply */
956 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
957 mutt_message ("%s", buf);
965 menu->oldcurrent = (Context->vcount && menu->current >= 0
967 Context->vcount) ? CURHDR->index : -1;
968 if (op == OP_TOGGLE_READ) {
969 char buf[LONG_STRING];
971 if (!Context->pattern
972 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
973 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
974 Context->pattern ? Context->pattern : ".*");
975 set_option (OPTHIDEREAD);
978 strfcpy (buf, Context->pattern + 8, sizeof (buf));
979 if (!*buf || strncmp (buf, ".*", 2) == 0)
980 snprintf (buf, sizeof (buf), "~A");
981 unset_option (OPTHIDEREAD);
983 FREE (&Context->pattern);
984 Context->pattern = safe_strdup (buf);
986 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
987 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
989 if (menu->oldcurrent >= 0) {
990 /* try to find what used to be the current message */
992 for (i = 0; i < Context->vcount; i++)
993 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
997 if (menu->current < 0)
1002 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1003 if ((Sort & SORT_MASK) == SORT_THREADS)
1004 mutt_draw_tree (Context);
1005 menu->redraw = REDRAW_FULL;
1017 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1020 oldcount = Context ? Context->msgcount : 0;
1023 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1026 if (check == M_NEW_MAIL || check == M_REOPENED)
1027 update_index (menu, Context, check, oldcount, index_hint);
1029 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1030 set_option (OPTSEARCHINVALID);
1037 clearok (stdscr, TRUE);
1038 menu->redraw = REDRAW_FULL;
1042 case OP_SEARCH_REVERSE:
1043 case OP_SEARCH_NEXT:
1044 case OP_SEARCH_OPPOSITE:
1048 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1049 menu->current = menu->oldcurrent;
1051 menu->redraw = REDRAW_MOTION;
1055 case OP_SORT_REVERSE:
1057 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1058 if (Context && Context->msgcount) {
1059 resort_index (menu);
1060 set_option (OPTSEARCHINVALID);
1069 if (tag && !option (OPTAUTOTAG)) {
1070 for (j = 0; j < Context->vcount; j++)
1071 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1072 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1075 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1076 Context->last_tag = CURHDR->tagged ? CURHDR :
1077 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1078 ? NULL : Context->last_tag);
1079 menu->redraw = REDRAW_STATUS;
1080 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1082 menu->redraw |= REDRAW_MOTION_RESYNCH;
1085 menu->redraw |= REDRAW_CURRENT;
1089 case OP_MAIN_TAG_PATTERN:
1093 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1094 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1097 case OP_MAIN_UNDELETE_PATTERN:
1104 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1107 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1109 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1112 case OP_MAIN_UNTAG_PATTERN:
1116 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1117 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1120 /* --------------------------------------------------------------------
1121 * The following operations can be performed inside of the pager.
1125 case OP_MAIN_IMAP_FETCH:
1126 if (Context->magic == M_IMAP)
1127 imap_check_mailbox (Context, &index_hint, 1);
1131 case OP_MAIN_SYNC_FOLDER:
1133 if (Context && !Context->msgcount)
1140 int oldvcount = Context->vcount;
1141 int oldcount = Context->msgcount;
1145 /* calculate the number of messages _above_ the cursor,
1146 * so we can keep the cursor on the current message
1148 for (j = 0; j <= menu->current; j++) {
1149 if (Context->hdrs[Context->v2r[j]]->deleted)
1153 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1154 if (Context->vcount != oldvcount)
1155 menu->current -= dcount;
1156 set_option (OPTSEARCHINVALID);
1158 else if (check == M_NEW_MAIL || check == M_REOPENED)
1159 update_index (menu, Context, check, oldcount, index_hint);
1162 * do a sanity check even if mx_sync_mailbox failed.
1165 if (menu->current < 0 || menu->current >= Context->vcount)
1166 menu->current = ci_first_message ();
1169 /* check for a fatal error, or all messages deleted */
1173 /* if we were in the pager, redisplay the message */
1174 if (menu->menu == MENU_PAGER) {
1175 op = OP_DISPLAY_MESSAGE;
1179 menu->redraw = REDRAW_FULL;
1182 case OP_SIDEBAR_OPEN:
1183 case OP_MAIN_CHANGE_FOLDER:
1184 case OP_MAIN_CHANGE_FOLDER_READONLY:
1186 case OP_MAIN_CHANGE_GROUP:
1187 case OP_MAIN_CHANGE_GROUP_READONLY:
1189 if (attach_msg || option (OPTREADONLY) ||
1191 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1193 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1199 cp = _("Open mailbox in read-only mode");
1201 cp = _("Open mailbox");
1205 unset_option (OPTNEWS);
1206 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1207 set_option (OPTNEWS);
1208 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1211 cp = _("Open newsgroup in read-only mode");
1213 cp = _("Open newsgroup");
1219 if (Context && Context->path)
1220 strncpy (buf, Context->path, sizeof (buf));
1221 mutt_buffy (buf, sizeof (buf));
1224 if (op == OP_SIDEBAR_OPEN) {
1225 strncpy (buf, NONULL(sidebar_get_current ()), sizeof (buf));
1227 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1231 CLEARLINE (LINES - 1);
1236 if (option (OPTNEWS)) {
1237 unset_option (OPTNEWS);
1238 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1242 mutt_expand_path (buf, sizeof (buf));
1243 sidebar_set_current (buf);
1244 if (mx_get_magic (buf) <= 0) {
1245 mutt_error (_("%s is not a mailbox."), buf);
1248 str_replace (&CurrentFolder, buf);
1253 #ifdef USE_COMPRESSED
1254 if (Context->compressinfo && Context->realpath)
1255 str_replace (&LastFolder, Context->realpath);
1259 str_replace (&LastFolder, Context->path);
1260 oldcount = Context ? Context->msgcount : 0;
1262 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1263 if (check == M_NEW_MAIL || check == M_REOPENED)
1264 update_index (menu, Context, check, oldcount, index_hint);
1266 set_option (OPTSEARCHINVALID);
1267 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1275 /* Set CurrentMenu to MENU_MAIN before executing any folder
1276 * hooks so that all the index menu functions are available to
1280 CurrentMenu = MENU_MAIN;
1281 mutt_folder_hook (buf);
1283 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1284 menu->current = ci_first_message ();
1290 /* mutt_buffy_check() must be done with mail-reader mode! */
1291 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1293 && (Context->magic ==
1294 M_NNTP)) ? IndexNewsHelp :
1297 mutt_clear_error ();
1298 mutt_buffy_check (1); /* force the buffy check after we have changed
1300 menu->redraw = REDRAW_FULL;
1301 set_option (OPTSEARCHINVALID);
1304 case OP_DISPLAY_MESSAGE:
1305 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1310 * toggle the weeding of headers so that a user can press the key
1311 * again while reading the message.
1313 if (op == OP_DISPLAY_HEADERS)
1314 toggle_option (OPTWEED);
1316 unset_option (OPTNEEDRESORT);
1318 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1319 mutt_uncollapse_thread (Context, CURHDR);
1320 mutt_set_virtual (Context);
1321 if (option (OPTUNCOLLAPSEJUMP))
1322 menu->current = mutt_thread_next_unread (Context, CURHDR);
1325 if ((op = mutt_display_message (CURHDR)) == -1) {
1326 unset_option (OPTNEEDRESORT);
1330 menu->menu = MENU_PAGER;
1331 menu->oldcurrent = menu->current;
1337 if (menu->menu == MENU_MAIN && attach_msg) {
1342 if ((menu->menu == MENU_MAIN)
1343 && (query_quadoption (OPT_QUIT,
1344 _("Exit Mutt-ng without saving?")) == M_YES))
1347 mx_fastclose_mailbox (Context);
1359 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1360 /* if we were in the pager, redisplay the message */
1361 if (menu->menu == MENU_PAGER) {
1362 op = OP_DISPLAY_MESSAGE;
1366 menu->redraw = REDRAW_CURRENT;
1369 case OP_MAIN_BREAK_THREAD:
1375 if ((Sort & SORT_MASK) != SORT_THREADS)
1376 mutt_error (_("Threading is not enabled."));
1380 HEADER *oldcur = CURHDR;
1382 mutt_break_thread (CURHDR);
1383 mutt_sort_headers (Context, 1);
1384 menu->current = oldcur->virtual;
1387 Context->changed = 1;
1388 mutt_message _("Thread broken");
1390 if (menu->menu == MENU_PAGER) {
1391 op = OP_DISPLAY_MESSAGE;
1395 menu->redraw |= REDRAW_INDEX;
1399 case OP_MAIN_LINK_THREADS:
1405 if ((Sort & SORT_MASK) != SORT_THREADS)
1406 mutt_error (_("Threading is not enabled."));
1408 else if (!CURHDR->env->message_id)
1409 mutt_error (_("No Message-ID: header available to link thread"));
1411 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1412 mutt_error (_("First, please tag a message to be linked here"));
1415 HEADER *oldcur = CURHDR;
1417 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1419 mutt_sort_headers (Context, 1);
1420 menu->current = oldcur->virtual;
1422 Context->changed = 1;
1423 mutt_message _("Threads linked");
1426 mutt_error (_("No thread linked"));
1429 if (menu->menu == MENU_PAGER) {
1430 op = OP_DISPLAY_MESSAGE;
1434 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1437 case OP_MAIN_NEXT_UNDELETED:
1441 if (menu->current >= Context->vcount - 1) {
1442 if (menu->menu == MENU_MAIN)
1443 mutt_error (_("You are on the last message."));
1447 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1448 menu->current = menu->oldcurrent;
1449 if (menu->menu == MENU_MAIN)
1450 mutt_error (_("No undeleted messages."));
1452 else if (menu->menu == MENU_PAGER) {
1453 op = OP_DISPLAY_MESSAGE;
1457 menu->redraw = REDRAW_MOTION;
1464 if (menu->current >= Context->vcount - 1) {
1465 if (menu->menu == MENU_MAIN)
1466 mutt_error (_("You are on the last message."));
1471 if (menu->menu == MENU_PAGER) {
1472 op = OP_DISPLAY_MESSAGE;
1476 menu->redraw = REDRAW_MOTION;
1479 case OP_MAIN_PREV_UNDELETED:
1483 if (menu->current < 1) {
1484 mutt_error (_("You are on the first message."));
1488 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1489 menu->current = menu->oldcurrent;
1490 if (menu->menu == MENU_MAIN)
1491 mutt_error (_("No undeleted messages."));
1493 else if (menu->menu == MENU_PAGER) {
1494 op = OP_DISPLAY_MESSAGE;
1498 menu->redraw = REDRAW_MOTION;
1505 if (menu->current < 1) {
1506 if (menu->menu == MENU_MAIN)
1507 mutt_error (_("You are on the first message."));
1512 if (menu->menu == MENU_PAGER) {
1513 op = OP_DISPLAY_MESSAGE;
1517 menu->redraw = REDRAW_MOTION;
1520 case OP_DECRYPT_COPY:
1521 case OP_DECRYPT_SAVE:
1525 case OP_COPY_MESSAGE:
1527 case OP_DECODE_COPY:
1528 case OP_DECODE_SAVE:
1531 if (mutt_save_message (tag ? NULL : CURHDR,
1532 (op == OP_DECRYPT_SAVE) ||
1533 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1534 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1535 (op == OP_DECRYPT_SAVE)
1536 || (op == OP_DECRYPT_COPY)
1537 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1544 menu->redraw |= REDRAW_INDEX;
1545 else if (option (OPTRESOLVE)) {
1546 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1547 menu->current = menu->oldcurrent;
1548 menu->redraw |= REDRAW_CURRENT;
1551 menu->redraw |= REDRAW_MOTION_RESYNCH;
1554 menu->redraw |= REDRAW_CURRENT;
1558 case OP_MAIN_NEXT_NEW:
1559 case OP_MAIN_NEXT_UNREAD:
1560 case OP_MAIN_PREV_NEW:
1561 case OP_MAIN_PREV_UNREAD:
1562 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1563 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1566 int first_unread = -1;
1574 for (j = 0; j != Context->vcount; j++) {
1575 #define CURHDRi Context->hdrs[Context->v2r[i]]
1576 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1577 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1579 if (i > Context->vcount - 1) {
1580 mutt_message _("Search wrapped to top.");
1588 mutt_message _("Search wrapped to bottom.");
1590 i = Context->vcount - 1;
1594 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1595 if (UNREAD (CURHDRi) && first_unread == -1)
1597 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1600 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1601 if (first_unread == -1)
1603 if ((!CURHDRi->old) && first_new == -1)
1607 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1610 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1611 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1612 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1617 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1618 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1619 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1621 menu->current = first_new;
1622 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1623 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1624 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1625 && first_unread != -1)
1626 menu->current = first_unread;
1628 if (menu->current == -1) {
1629 menu->current = menu->oldcurrent;
1630 mutt_error ("%s%s.",
1631 (op == OP_MAIN_NEXT_NEW
1633 OP_MAIN_PREV_NEW) ? _("No new messages") :
1634 _("No unread messages"),
1635 Context->pattern ? _(" in this limited view") : "");
1637 else if (menu->menu == MENU_PAGER) {
1638 op = OP_DISPLAY_MESSAGE;
1642 menu->redraw = REDRAW_MOTION;
1645 case OP_FLAG_MESSAGE:
1652 if (Context->magic == M_POP) {
1654 mutt_error (_("Can't change 'important' flag on POP server."));
1661 CHECK_IMAP_ACL (IMAP_ACL_WRITE);
1665 if (Context->magic == M_NNTP) {
1667 mutt_error (_("Can't change 'important' flag on NNTP server."));
1674 for (j = 0; j < Context->vcount; j++) {
1675 if (Context->hdrs[Context->v2r[j]]->tagged)
1676 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1677 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1680 menu->redraw |= REDRAW_INDEX;
1683 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1684 if (option (OPTRESOLVE)) {
1685 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1686 menu->current = menu->oldcurrent;
1687 menu->redraw = REDRAW_CURRENT;
1690 menu->redraw = REDRAW_MOTION_RESYNCH;
1693 menu->redraw = REDRAW_CURRENT;
1695 menu->redraw |= REDRAW_STATUS;
1705 CHECK_IMAP_ACL (IMAP_ACL_SEEN);
1709 for (j = 0; j < Context->vcount; j++) {
1710 if (Context->hdrs[Context->v2r[j]]->tagged) {
1711 if (Context->hdrs[Context->v2r[j]]->read ||
1712 Context->hdrs[Context->v2r[j]]->old)
1713 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1716 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1720 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1723 if (CURHDR->read || CURHDR->old)
1724 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1726 mutt_set_flag (Context, CURHDR, M_READ, 1);
1728 if (option (OPTRESOLVE)) {
1729 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1730 menu->current = menu->oldcurrent;
1731 menu->redraw = REDRAW_CURRENT;
1734 menu->redraw = REDRAW_MOTION_RESYNCH;
1737 menu->redraw = REDRAW_CURRENT;
1738 menu->redraw |= REDRAW_STATUS;
1742 case OP_TOGGLE_WRITE:
1745 if (mx_toggle_write (Context) == 0)
1746 menu->redraw |= REDRAW_STATUS;
1749 case OP_MAIN_NEXT_THREAD:
1750 case OP_MAIN_NEXT_SUBTHREAD:
1751 case OP_MAIN_PREV_THREAD:
1752 case OP_MAIN_PREV_SUBTHREAD:
1757 case OP_MAIN_NEXT_THREAD:
1758 menu->current = mutt_next_thread (CURHDR);
1761 case OP_MAIN_NEXT_SUBTHREAD:
1762 menu->current = mutt_next_subthread (CURHDR);
1765 case OP_MAIN_PREV_THREAD:
1766 menu->current = mutt_previous_thread (CURHDR);
1769 case OP_MAIN_PREV_SUBTHREAD:
1770 menu->current = mutt_previous_subthread (CURHDR);
1774 if (menu->current < 0) {
1775 menu->current = menu->oldcurrent;
1776 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1777 mutt_error (_("No more threads."));
1780 mutt_error (_("You are on the first thread."));
1782 else if (menu->menu == MENU_PAGER) {
1783 op = OP_DISPLAY_MESSAGE;
1787 menu->redraw = REDRAW_MOTION;
1790 case OP_MAIN_PARENT_MESSAGE:
1795 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1796 menu->current = menu->oldcurrent;
1798 else if (menu->menu == MENU_PAGER) {
1799 op = OP_DISPLAY_MESSAGE;
1803 menu->redraw = REDRAW_MOTION;
1806 case OP_MAIN_SET_FLAG:
1807 case OP_MAIN_CLEAR_FLAG:
1814 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1817 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1819 menu->redraw = REDRAW_STATUS;
1821 menu->redraw |= REDRAW_INDEX;
1822 else if (option (OPTRESOLVE)) {
1823 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1824 menu->current = menu->oldcurrent;
1825 menu->redraw |= REDRAW_CURRENT;
1828 menu->redraw |= REDRAW_MOTION_RESYNCH;
1831 menu->redraw |= REDRAW_CURRENT;
1835 case OP_MAIN_COLLAPSE_THREAD:
1839 if ((Sort & SORT_MASK) != SORT_THREADS) {
1840 mutt_error (_("Threading is not enabled."));
1845 if (CURHDR->collapsed) {
1846 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1847 mutt_set_virtual (Context);
1848 if (option (OPTUNCOLLAPSEJUMP))
1849 menu->current = mutt_thread_next_unread (Context, CURHDR);
1851 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1852 menu->current = mutt_collapse_thread (Context, CURHDR);
1853 mutt_set_virtual (Context);
1856 mutt_error (_("Thread contains unread messages."));
1861 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1865 case OP_MAIN_COLLAPSE_ALL:
1869 if ((Sort & SORT_MASK) != SORT_THREADS) {
1870 mutt_error (_("Threading is not enabled."));
1877 THREAD *thread, *top;
1880 if (CURHDR->collapsed)
1881 final = mutt_uncollapse_thread (Context, CURHDR);
1882 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1883 final = mutt_collapse_thread (Context, CURHDR);
1885 final = CURHDR->virtual;
1887 base = Context->hdrs[Context->v2r[final]];
1889 top = Context->tree;
1890 Context->collapsed = !Context->collapsed;
1891 while ((thread = top) != NULL) {
1892 while (!thread->message)
1893 thread = thread->child;
1894 h = thread->message;
1896 if (h->collapsed != Context->collapsed) {
1898 mutt_uncollapse_thread (Context, h);
1899 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1900 mutt_collapse_thread (Context, h);
1905 mutt_set_virtual (Context);
1906 for (j = 0; j < Context->vcount; j++) {
1907 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1913 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1917 /* --------------------------------------------------------------------
1918 * These functions are invoked directly from the internal-pager
1921 case OP_BOUNCE_MESSAGE:
1926 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1929 case OP_CREATE_ALIAS:
1931 mutt_create_alias (Context
1932 && Context->vcount ? CURHDR->env : NULL, NULL);
1933 MAYBE_REDRAW (menu->redraw);
1934 menu->redraw |= REDRAW_CURRENT;
1939 mutt_query_menu (NULL, 0);
1940 MAYBE_REDRAW (menu->redraw);
1943 case OP_PURGE_MESSAGE:
1951 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1955 mutt_tag_set_flag (M_DELETE, 1);
1956 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1957 if (option (OPTDELETEUNTAG))
1958 mutt_tag_set_flag (M_TAG, 0);
1959 menu->redraw = REDRAW_INDEX;
1962 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1963 mutt_set_flag (Context, CURHDR, M_PURGED,
1964 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1965 if (option (OPTDELETEUNTAG))
1966 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1967 if (option (OPTRESOLVE)) {
1968 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1969 menu->current = menu->oldcurrent;
1970 menu->redraw = REDRAW_CURRENT;
1972 else if (menu->menu == MENU_PAGER) {
1973 op = OP_DISPLAY_MESSAGE;
1977 menu->redraw |= REDRAW_MOTION_RESYNCH;
1980 menu->redraw = REDRAW_CURRENT;
1982 menu->redraw |= REDRAW_STATUS;
1985 case OP_DELETE_THREAD:
1986 case OP_DELETE_SUBTHREAD:
1993 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1996 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1997 op == OP_DELETE_THREAD ? 0 : 1);
2000 if (option (OPTDELETEUNTAG))
2001 mutt_thread_set_flag (CURHDR, M_TAG, 0,
2002 op == OP_DELETE_THREAD ? 0 : 1);
2003 if (option (OPTRESOLVE))
2004 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
2005 menu->current = menu->oldcurrent;
2006 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2012 if (Context && Context->magic == M_NNTP) {
2013 if (mutt_newsgroup_catchup (CurrentNewsSrv,
2014 ((NNTP_DATA *) Context->data)->group))
2015 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2020 case OP_DISPLAY_ADDRESS:
2024 mutt_display_address (CURHDR->env);
2027 case OP_ENTER_COMMAND:
2029 CurrentMenu = MENU_MAIN;
2030 mutt_enter_command ();
2031 mutt_check_rescore (Context);
2032 if (option (OPTFORCEREDRAWINDEX))
2033 menu->redraw = REDRAW_FULL;
2034 unset_option (OPTFORCEREDRAWINDEX);
2035 unset_option (OPTFORCEREDRAWPAGER);
2038 case OP_EDIT_MESSAGE:
2046 if (Context->magic == M_POP) {
2048 mutt_error (_("Can't edit message on POP server."));
2055 CHECK_IMAP_ACL (IMAP_ACL_INSERT);
2059 if (Context->magic == M_NNTP) {
2061 mutt_error (_("Can't edit message on newsserver."));
2067 if (option (OPTPGPAUTODEC)
2068 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2069 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2070 mutt_edit_message (Context, tag ? NULL : CURHDR);
2071 menu->redraw = REDRAW_FULL;
2075 case OP_FORWARD_MESSAGE:
2080 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2081 menu->redraw = REDRAW_FULL;
2085 case OP_FORGET_PASSPHRASE:
2086 crypt_forget_passphrase ();
2089 case OP_GROUP_REPLY:
2094 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2095 tag ? NULL : CURHDR);
2096 menu->redraw = REDRAW_FULL;
2104 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2105 tag ? NULL : CURHDR);
2106 menu->redraw = REDRAW_FULL;
2112 ci_send_message (0, NULL, NULL, Context, NULL);
2113 menu->redraw = REDRAW_FULL;
2117 if (!(WithCrypto & APPLICATION_PGP))
2120 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2121 menu->redraw = REDRAW_FULL;
2125 case OP_EXTRACT_KEYS:
2130 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2131 menu->redraw = REDRAW_FULL;
2135 case OP_CHECK_TRADITIONAL:
2136 if (!(WithCrypto & APPLICATION_PGP))
2140 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2141 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2143 if (menu->menu == MENU_PAGER) {
2144 op = OP_DISPLAY_MESSAGE;
2153 mutt_pipe_message (tag ? NULL : CURHDR);
2154 MAYBE_REDRAW (menu->redraw);
2161 mutt_print_message (tag ? NULL : CURHDR);
2164 case OP_MAIN_READ_THREAD:
2165 case OP_MAIN_READ_SUBTHREAD:
2172 CHECK_IMAP_ACL (IMAP_ACL_SEEN);
2175 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2176 op == OP_MAIN_READ_THREAD ? 0 : 1);
2179 if (option (OPTRESOLVE)) {
2180 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2181 mutt_next_thread (CURHDR) :
2182 mutt_next_subthread (CURHDR))) == -1)
2183 menu->current = menu->oldcurrent;
2185 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2189 case OP_RECALL_MESSAGE:
2192 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2193 menu->redraw = REDRAW_FULL;
2203 for (j = 0; j < Context->vcount; j++) {
2204 if (Context->hdrs[Context->v2r[j]]->tagged)
2205 mutt_resend_message (NULL, Context,
2206 Context->hdrs[Context->v2r[j]]);
2210 mutt_resend_message (NULL, Context, CURHDR);
2212 menu->redraw = REDRAW_FULL;
2218 case OP_FORWARD_TO_GROUP:
2221 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2222 Context && Context->msgcount == 0) {
2223 mutt_error (_("There are no messages."));
2226 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2227 safe_strcasecmp (CURHDR->env->followup_to, "poster") ||
2228 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2229 _("Reply by mail as poster prefers?")) !=
2231 if (Context && Context->magic == M_NNTP
2232 && !((NNTP_DATA *) Context->data)->allowed
2233 && query_quadoption (OPT_TOMODERATED,
2235 ("Posting to this group not allowed, may be moderated. Continue?"))
2239 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2242 if (op == OP_FOLLOWUP)
2243 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2244 tag ? NULL : CURHDR);
2246 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2247 tag ? NULL : CURHDR);
2249 menu->redraw = REDRAW_FULL;
2259 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2260 menu->redraw = REDRAW_FULL;
2263 case OP_SHELL_ESCAPE:
2265 mutt_shell_escape ();
2266 MAYBE_REDRAW (menu->redraw);
2270 case OP_TAG_SUBTHREAD:
2274 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2275 op == OP_TAG_THREAD ? 0 : 1);
2278 if (option (OPTRESOLVE)) {
2279 menu->current = mutt_next_thread (CURHDR);
2281 if (menu->current == -1)
2282 menu->current = menu->oldcurrent;
2284 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2295 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2299 mutt_tag_set_flag (M_DELETE, 0);
2300 mutt_tag_set_flag (M_PURGED, 0);
2301 menu->redraw = REDRAW_INDEX;
2304 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2305 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2306 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2308 menu->redraw = REDRAW_MOTION_RESYNCH;
2311 menu->redraw = REDRAW_CURRENT;
2313 menu->redraw |= REDRAW_STATUS;
2316 case OP_UNDELETE_THREAD:
2317 case OP_UNDELETE_SUBTHREAD:
2324 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2327 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2328 op == OP_UNDELETE_THREAD ? 0 : 1)
2329 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2330 op == OP_UNDELETE_THREAD ? 0 : 1);
2333 if (option (OPTRESOLVE)) {
2334 if (op == OP_UNDELETE_THREAD)
2335 menu->current = mutt_next_thread (CURHDR);
2337 menu->current = mutt_next_subthread (CURHDR);
2339 if (menu->current == -1)
2340 menu->current = menu->oldcurrent;
2342 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2352 menu->redraw = REDRAW_FULL;
2355 case OP_VIEW_ATTACHMENTS:
2358 mutt_view_attachments (CURHDR);
2359 if (CURHDR->attach_del)
2360 Context->changed = 1;
2361 menu->redraw = REDRAW_FULL;
2371 case OP_SIDEBAR_SCROLL_UP:
2372 case OP_SIDEBAR_SCROLL_DOWN:
2373 case OP_SIDEBAR_NEXT:
2374 case OP_SIDEBAR_PREV:
2375 case OP_SIDEBAR_NEXT_NEW:
2376 case OP_SIDEBAR_PREV_NEW:
2377 sidebar_scroll (op, menu->menu);
2380 if (menu->menu == MENU_MAIN)
2381 km_error_key (MENU_MAIN);
2384 if (menu->menu == MENU_PAGER) {
2385 menu->menu = MENU_MAIN;
2386 menu->redraw = REDRAW_FULL;
2388 set_option (OPTWEED); /* turn header weeding back on. */
2397 /* Close all open IMAP connections */
2402 /* Close all open NNTP connections */
2407 mutt_menuDestroy (&menu);
2411 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2418 for (color = ColorIndexList; color; color = color->next)
2419 if (mutt_pattern_exec
2420 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2421 curhdr->pair = color->pair;
2424 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];