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"
47 #include "lib/debug.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_IN_MAILBOX if (!Context) \
67 mutt_error (_(No_mailbox_is_open)); \
71 #define CHECK_MSGCOUNT if (!Context) \
74 mutt_error(_(No_mailbox_is_open)); \
77 else if (!Context->msgcount) \
80 mutt_error(_(There_are_no_messages)); \
84 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
87 mutt_error(_(No_visible)); \
92 #define CHECK_READONLY if (Context->readonly) \
95 mutt_error(_(Mailbox_is_read_only)); \
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 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
116 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
117 int edgemsgno, reverse = Sort & SORT_REVERSE;
118 HEADER *h = Context->hdrs[Context->v2r[num]];
121 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
122 flag |= M_FORMAT_TREE; /* display the thread tree */
123 if (h->display_subject)
124 flag |= M_FORMAT_FORCESUBJ;
127 if (menu->top + menu->pagelen > menu->max)
128 edgemsgno = Context->v2r[menu->max - 1];
130 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
133 edgemsgno = Context->v2r[menu->top];
135 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
139 /* if no ancestor is visible on current screen, provisionally force
141 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
143 flag |= M_FORMAT_FORCESUBJ;
146 else if (tmp->message->virtual >= 0)
149 if (flag & M_FORMAT_FORCESUBJ) {
150 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
154 /* ...but if a previous sibling is available, don't force it */
155 if (reverse ? tmp->message->msgno >
156 edgemsgno : tmp->message->msgno < edgemsgno)
158 else if (tmp->message->virtual >= 0) {
159 flag &= ~M_FORMAT_FORCESUBJ;
167 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
170 int index_color (int index_no)
172 HEADER *h = Context->hdrs[Context->v2r[index_no]];
177 mutt_set_header_color (Context, h);
181 static int ci_next_undeleted (int msgno)
185 for (i = msgno + 1; i < Context->vcount; i++)
186 if (!Context->hdrs[Context->v2r[i]]->deleted)
191 static int ci_previous_undeleted (int msgno)
195 for (i = msgno - 1; i >= 0; i--)
196 if (!Context->hdrs[Context->v2r[i]]->deleted)
201 /* Return the index of the first new message, or failing that, the first
204 static int ci_first_message (void)
208 if (Context && Context->msgcount) {
209 for (i = 0; i < Context->vcount; i++) {
210 if (!Context->hdrs[Context->v2r[i]]->read &&
211 !Context->hdrs[Context->v2r[i]]->deleted) {
212 if (!Context->hdrs[Context->v2r[i]]->old)
221 /* If Sort is reverse and not threaded, the latest message is first.
222 * If Sort is threaded, the latest message is first iff exactly one
223 * of Sort and SortAux are reverse.
225 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
226 ((Sort & SORT_MASK) == SORT_THREADS &&
227 ((Sort ^ SortAux) & SORT_REVERSE)))
230 return (Context->vcount ? Context->vcount - 1 : 0);
235 /* This should be in mx.c, but it only gets used here. */
236 static int mx_toggle_write (CONTEXT * ctx)
242 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
247 if (ctx->dontwrite) {
249 mutt_message (_("Changes to folder will be written on folder exit."));
253 mutt_message (_("Changes to folder will not be written."));
259 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
260 int oldcount, int index_hint)
262 /* store pointers to the newly added messages */
263 HEADER **save_new = NULL;
266 /* take note of the current message */
268 if (menu->current < Context->vcount)
269 menu->oldcurrent = index_hint;
271 oldcount = 0; /* invalid message number! */
274 /* We are in a limited view. Check if the new message(s) satisfy
275 * the limit criteria. If they do, set their virtual msgno so that
276 * they will be visible in the limited view */
277 if (Context->pattern) {
278 #define THIS_BODY Context->hdrs[j]->content
279 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
280 if (mutt_pattern_exec
281 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
283 Context->hdrs[j]->virtual = Context->vcount;
284 Context->v2r[Context->vcount] = j;
285 Context->hdrs[j]->limited = 1;
288 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
294 /* save the list of new messages */
295 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
297 (HEADER **) mem_malloc (sizeof (HEADER *) *
298 (Context->msgcount - oldcount));
299 for (j = oldcount; j < Context->msgcount; j++)
300 save_new[j - oldcount] = Context->hdrs[j];
303 /* if the mailbox was reopened, need to rethread from scratch */
304 mutt_sort_headers (Context, (check == M_REOPENED));
306 /* uncollapse threads with new mail */
307 if ((Sort & SORT_MASK) == SORT_THREADS) {
308 if (check == M_REOPENED) {
311 Context->collapsed = 0;
313 for (h = Context->tree; h; h = h->next) {
314 for (j = h; !j->message; j = j->child);
315 mutt_uncollapse_thread (Context, j->message);
317 mutt_set_virtual (Context);
320 for (j = 0; j < Context->msgcount - oldcount; j++) {
323 for (k = 0; k < Context->msgcount; k++) {
324 HEADER *h = Context->hdrs[k];
326 if (h == save_new[j] && (!Context->pattern || h->limited))
327 mutt_uncollapse_thread (Context, h);
330 mem_free (&save_new);
331 mutt_set_virtual (Context);
337 /* restore the current message to the message it was pointing to */
338 for (j = 0; j < Context->vcount; j++) {
339 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
346 if (menu->current < 0)
347 menu->current = ci_first_message ();
350 static void resort_index (MUTTMENU * menu)
353 HEADER *current = CURHDR;
356 mutt_sort_headers (Context, 0);
357 /* Restore the current message */
359 for (i = 0; i < Context->vcount; i++) {
360 if (Context->hdrs[Context->v2r[i]] == current) {
366 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
367 menu->current = mutt_parent_message (Context, current);
369 if (menu->current < 0)
370 menu->current = ci_first_message ();
372 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
375 struct mapping_t IndexHelp[] = {
376 {N_("Quit"), OP_QUIT},
377 {N_("Del"), OP_DELETE},
378 {N_("Undel"), OP_UNDELETE},
379 {N_("Save"), OP_SAVE},
380 {N_("Mail"), OP_MAIL},
381 {N_("Reply"), OP_REPLY},
382 {N_("Group"), OP_GROUP_REPLY},
383 {N_("Help"), OP_HELP},
388 struct mapping_t IndexNewsHelp[] = {
389 {N_("Quit"), OP_QUIT},
390 {N_("Del"), OP_DELETE},
391 {N_("Undel"), OP_UNDELETE},
392 {N_("Save"), OP_SAVE},
393 {N_("Post"), OP_POST},
394 {N_("Followup"), OP_FOLLOWUP},
395 {N_("Catchup"), OP_CATCHUP},
396 {N_("Help"), OP_HELP},
401 /* This function handles the message index window as well as commands returned
402 * from the pager (MENU_PAGER).
404 int mutt_index_menu (void)
406 char buf[LONG_STRING], helpstr[SHORT_STRING];
409 int done = 0; /* controls when to exit the "event" loop */
411 int tag = 0; /* has the tag-prefix command been pressed? */
416 char *cp; /* temporary variable. */
417 int index_hint; /* used to restore cursor position */
418 int do_buffy_notify = 1;
419 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
420 int attach_msg = option (OPTATTACHMSG);
422 menu = mutt_new_menu ();
423 menu->menu = MENU_MAIN;
425 menu->pagelen = LINES - 3;
426 menu->make_entry = index_make_entry;
427 menu->color = index_color;
428 menu->current = ci_first_message ();
429 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
432 && (Context->magic ==
433 M_NNTP)) ? IndexNewsHelp :
438 buffy_check (1); /* force the buffy check after we enter the folder */
439 /* record folder we open to place sidebar indicator properly */
440 if (Context && Context->path)
441 sidebar_set_current (Context->path);
445 tag = 0; /* clear the tag-prefix */
447 menu->max = Context ? Context->vcount : 0;
448 oldcount = Context ? Context->msgcount : 0;
450 /* check if we need to resort the index because just about
451 * any 'op' below could do mutt_enter_command(), either here or
452 * from any new menu launched, and change $sort/$sort_aux
454 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
457 if (option (OPTREDRAWTREE) && Context && Context->msgcount
458 && (Sort & SORT_MASK) == SORT_THREADS) {
459 mutt_draw_tree (Context);
460 menu->redraw |= REDRAW_STATUS;
461 unset_option (OPTREDRAWTREE);
464 if (Context && !attach_msg) {
467 /* check for new mail in the mailbox. If nonzero, then something has
468 * changed about the file (either we got new mail or the file was
469 * modified underneath us.)
473 imap_allow_reopen (Context);
476 index_hint = (Context->vcount && menu->current >= 0
477 && menu->current < Context->vcount) ? CURHDR->index : 0;
479 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
480 if (!Context->path) {
481 /* fatal error occurred */
483 menu->redraw = REDRAW_FULL;
485 set_option (OPTSEARCHINVALID);
487 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
488 update_index (menu, Context, check, oldcount, index_hint);
490 /* notify the user of new mail */
491 if (check == M_REOPENED)
493 ("Mailbox was externally modified. Flags may be wrong."));
494 else if (check == M_NEW_MAIL) {
495 /* on new mail: redraw sidebar */
496 sidebar_draw (CurrentMenu);
497 mutt_message (_("New mail in this mailbox."));
499 if (option (OPTBEEPNEW))
502 else if (check == M_FLAGS)
503 mutt_message (_("Mailbox was externally modified."));
505 /* avoid the message being overwritten by buffy */
508 menu->redraw = REDRAW_FULL;
509 menu->max = Context->vcount;
511 set_option (OPTSEARCHINVALID);
517 imap_disallow_reopen (Context);
521 /* check for new mail in the incoming folders */
523 if ((newcount = buffy_check (0)) != oldcount) {
524 menu->redraw |= REDRAW_STATUS;
525 menu->redraw |= REDRAW_SIDEBAR;
527 if (do_buffy_notify) {
528 if (buffy_notify () && option (OPTBEEPNEW))
537 if (menu->redraw & REDRAW_SIDEBAR)
538 sidebar_draw (menu->menu);
539 if (menu->redraw & REDRAW_FULL) {
540 menu_redraw_full (menu);
541 sidebar_draw (menu->menu);
545 if (menu->menu == MENU_MAIN) {
546 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
547 menu_check_recenter (menu);
549 if (menu->redraw & REDRAW_INDEX) {
550 menu_redraw_index (menu);
551 menu->redraw |= REDRAW_STATUS;
553 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
554 menu_redraw_motion (menu);
555 else if (menu->redraw & REDRAW_CURRENT)
556 menu_redraw_current (menu);
559 if (menu->redraw & REDRAW_STATUS) {
561 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
563 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
564 SETCOLOR (MT_COLOR_STATUS);
565 BKGDSET (MT_COLOR_STATUS);
566 mutt_paddstr (COLS, buf);
567 SETCOLOR (MT_COLOR_NORMAL);
568 BKGDSET (MT_COLOR_NORMAL);
569 sidebar_set_buffystats (Context);
570 menu->redraw &= ~REDRAW_STATUS;
571 if (option (OPTXTERMSETTITLES)) {
572 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
573 mutt_xterm_set_title (buf);
574 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
575 mutt_xterm_set_icon (buf);
580 if (menu->current < menu->max)
581 menu->oldcurrent = menu->current;
583 menu->oldcurrent = -1;
585 if (option (OPTARROWCURSOR))
586 move (menu->current - menu->top + menu->offset, 2);
587 else if (option (OPTBRAILLEFRIENDLY))
588 move (menu->current - menu->top + menu->offset, 0);
590 move (menu->current - menu->top + menu->offset, COLS - 1);
593 op = km_dokey (MENU_MAIN);
595 debug_print (4, ("Got op %d\n", op));
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);
615 continue; /* either user abort or timeout */
619 /* special handling for the tag-prefix function */
620 if (op == OP_TAG_PREFIX) {
622 mutt_error (_("No mailbox is open."));
627 if (!Context->tagged) {
628 mutt_error (_("No tagged messages."));
634 /* give visual indication that the next command is a tag- command */
635 mvaddstr (LINES - 1, 0, "tag-");
638 /* get the real command */
639 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
640 /* abort tag sequence */
641 CLEARLINE (LINES - 1);
645 else if (option (OPTAUTOTAG) && Context && Context->tagged)
648 if (op == OP_TAG_PREFIX_COND) {
650 mutt_error (_("No mailbox is open."));
655 if (!Context->tagged) {
658 while (UngetCount > 0) {
660 if (tmp.op == OP_END_COND)
663 mutt_message (_("Nothing to do."));
669 /* give visual indication that the next command is a tag- command */
670 mvaddstr (LINES - 1, 0, "tag-");
673 /* get the real command */
674 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
675 /* abort tag sequence */
676 CLEARLINE (LINES - 1);
684 if (menu->current < menu->max)
685 menu->oldcurrent = menu->current;
687 menu->oldcurrent = -1;
689 mutt_curs_set (1); /* fallback from the pager */
693 unset_option (OPTNEWS); /* for any case */
698 /* ----------------------------------------------------------------------
703 menu_bottom_page (menu);
706 menu_first_entry (menu);
709 menu_middle_page (menu);
715 menu_half_down (menu);
718 menu_next_line (menu);
721 menu_prev_line (menu);
724 menu_next_page (menu);
727 menu_prev_page (menu);
730 menu_last_entry (menu);
733 menu_top_page (menu);
736 menu_current_top (menu);
738 case OP_CURRENT_MIDDLE:
739 menu_current_middle (menu);
741 case OP_CURRENT_BOTTOM:
742 menu_current_bottom (menu);
749 if (Context->magic == M_NNTP) {
752 if (op == OP_GET_MESSAGE) {
754 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0)
759 LIST *ref = CURHDR->env->references;
762 mutt_error (_("Article has no parent reference!"));
766 strfcpy (buf, ref->data, sizeof (buf));
768 if (!Context->id_hash)
769 Context->id_hash = mutt_make_id_hash (Context);
770 if ((h = hash_find (Context->id_hash, buf))) {
771 if (h->virtual != -1) {
772 menu->current = h->virtual;
773 menu->redraw = REDRAW_MOTION_RESYNCH;
775 else if (h->collapsed) {
776 mutt_uncollapse_thread (Context, h);
777 mutt_set_virtual (Context);
778 menu->current = h->virtual;
779 menu->redraw = REDRAW_MOTION_RESYNCH;
782 mutt_error (_("Message not visible in limited view."));
785 if (nntp_check_msgid (Context, buf) == 0) {
786 h = Context->hdrs[Context->msgcount - 1];
787 mutt_sort_headers (Context, 0);
788 menu->current = h->virtual;
789 menu->redraw = REDRAW_FULL;
792 mutt_error (_("Article %s not found on server"), buf);
797 case OP_GET_CHILDREN:
798 case OP_RECONSTRUCT_THREAD:
800 if (Context->magic == M_NNTP) {
802 int old = CURHDR->index, i;
804 if (!CURHDR->env->message_id) {
805 mutt_error (_("No Message-Id. Unable to perform operation"));
810 if (!Context->id_hash)
811 Context->id_hash = mutt_make_id_hash (Context);
812 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
814 if (op == OP_RECONSTRUCT_THREAD) {
815 LIST *ref = CURHDR->env->references;
818 nntp_check_msgid (Context, ref->data);
819 /* the last msgid in References is the root message */
821 strfcpy (buf, ref->data, sizeof (buf));
825 mutt_message (_("Check for children of message..."));
827 if (nntp_check_children (Context, buf) == 0) {
828 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
829 h = hash_find (Context->id_hash, buf);
830 /* if the root message was retrieved, move to it */
832 menu->current = h->virtual;
833 else /* try to restore old position */
834 for (i = 0; i < Context->msgcount; i++)
835 if (Context->hdrs[i]->index == old) {
836 menu->current = Context->hdrs[i]->virtual;
837 /* As an added courtesy, recenter the menu
838 * with the current entry at the middle of the screen */
839 menu_check_recenter (menu);
840 menu_current_middle (menu);
843 menu->redraw = REDRAW_FULL;
853 if (isdigit (LastKey))
854 mutt_ungetch (LastKey, 0);
856 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
860 if (!isdigit ((unsigned char) buf[0])) {
861 mutt_error (_("Argument must be a message number."));
867 if (i > 0 && i <= Context->msgcount) {
868 for (j = i - 1; j < Context->msgcount; j++) {
869 if (Context->hdrs[j]->virtual != -1)
872 if (j >= Context->msgcount) {
873 for (j = i - 2; j >= 0; j--) {
874 if (Context->hdrs[j]->virtual != -1)
880 menu->current = Context->hdrs[j]->virtual;
881 if (menu->menu == MENU_PAGER) {
882 op = OP_DISPLAY_MESSAGE;
886 menu->redraw = REDRAW_MOTION;
889 mutt_error (_("That message is not visible."));
892 mutt_error (_("Invalid message number."));
896 /* --------------------------------------------------------------------
897 * `index' specific commands
900 case OP_MAIN_DELETE_PATTERN:
906 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
909 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
910 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
914 case OP_MAIN_FETCH_MAIL:
918 menu->redraw = REDRAW_FULL;
924 mutt_help (MENU_MAIN);
925 menu->redraw = REDRAW_FULL;
928 case OP_MAIN_SHOW_LIMIT:
930 if (!Context->pattern)
931 mutt_message (_("No limit pattern is in effect."));
936 /* i18n: ask for a limit to apply */
937 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
938 mutt_message ("%s", buf);
946 menu->oldcurrent = (Context->vcount && menu->current >= 0
948 Context->vcount) ? CURHDR->index : -1;
949 if (op == OP_TOGGLE_READ) {
950 char buf[LONG_STRING];
952 if (!Context->pattern
953 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
954 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
955 Context->pattern ? Context->pattern : ".*");
956 set_option (OPTHIDEREAD);
959 strfcpy (buf, Context->pattern + 8, sizeof (buf));
960 if (!*buf || strncmp (buf, ".*", 2) == 0)
961 snprintf (buf, sizeof (buf), "~A");
962 unset_option (OPTHIDEREAD);
964 mem_free (&Context->pattern);
965 Context->pattern = str_dup (buf);
967 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
968 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
970 if (menu->oldcurrent >= 0) {
971 /* try to find what used to be the current message */
973 for (i = 0; i < Context->vcount; i++)
974 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
978 if (menu->current < 0)
983 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
984 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
985 mutt_draw_tree (Context);
986 menu->redraw = REDRAW_FULL;
998 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1001 oldcount = Context ? Context->msgcount : 0;
1004 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1007 if (check == M_NEW_MAIL || check == M_REOPENED)
1008 update_index (menu, Context, check, oldcount, index_hint);
1010 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1011 set_option (OPTSEARCHINVALID);
1018 clearok (stdscr, TRUE);
1019 menu->redraw = REDRAW_FULL;
1023 case OP_SEARCH_REVERSE:
1024 case OP_SEARCH_NEXT:
1025 case OP_SEARCH_OPPOSITE:
1029 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1030 menu->current = menu->oldcurrent;
1032 menu->redraw = REDRAW_MOTION;
1036 case OP_SORT_REVERSE:
1038 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1039 if (Context && Context->msgcount) {
1040 resort_index (menu);
1041 set_option (OPTSEARCHINVALID);
1050 if (tag && !option (OPTAUTOTAG)) {
1051 for (j = 0; j < Context->vcount; j++)
1052 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1053 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1056 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1057 Context->last_tag = CURHDR->tagged ? CURHDR :
1058 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1059 ? NULL : Context->last_tag);
1060 menu->redraw = REDRAW_STATUS;
1061 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1063 menu->redraw |= REDRAW_MOTION_RESYNCH;
1066 menu->redraw |= REDRAW_CURRENT;
1070 case OP_MAIN_TAG_PATTERN:
1074 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1075 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1078 case OP_MAIN_UNDELETE_PATTERN:
1084 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1086 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1088 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1091 case OP_MAIN_UNTAG_PATTERN:
1095 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1096 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1099 /* --------------------------------------------------------------------
1100 * The following operations can be performed inside of the pager.
1104 case OP_MAIN_IMAP_FETCH:
1105 if (Context->magic == M_IMAP)
1106 imap_check_mailbox (Context, &index_hint, 1);
1110 case OP_MAIN_SYNC_FOLDER:
1112 if (Context && !Context->msgcount)
1119 int oldvcount = Context->vcount;
1120 int oldcount = Context->msgcount;
1124 /* calculate the number of messages _above_ the cursor,
1125 * so we can keep the cursor on the current message
1127 for (j = 0; j <= menu->current; j++) {
1128 if (Context->hdrs[Context->v2r[j]]->deleted)
1132 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1133 if (Context->vcount != oldvcount)
1134 menu->current -= dcount;
1135 set_option (OPTSEARCHINVALID);
1137 else if (check == M_NEW_MAIL || check == M_REOPENED)
1138 update_index (menu, Context, check, oldcount, index_hint);
1141 * do a sanity check even if mx_sync_mailbox failed.
1144 if (menu->current < 0 || menu->current >= Context->vcount)
1145 menu->current = ci_first_message ();
1148 /* check for a fatal error, or all messages deleted */
1150 mem_free (&Context);
1152 /* if we were in the pager, redisplay the message */
1153 if (menu->menu == MENU_PAGER) {
1154 op = OP_DISPLAY_MESSAGE;
1158 menu->redraw = REDRAW_FULL;
1161 case OP_SIDEBAR_OPEN:
1162 case OP_MAIN_CHANGE_FOLDER:
1163 case OP_MAIN_CHANGE_FOLDER_READONLY:
1165 case OP_MAIN_CHANGE_GROUP:
1166 case OP_MAIN_CHANGE_GROUP_READONLY:
1168 if (attach_msg || option (OPTREADONLY) ||
1170 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1172 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1178 cp = _("Open mailbox in read-only mode");
1180 cp = _("Open mailbox");
1184 unset_option (OPTNEWS);
1185 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1186 set_option (OPTNEWS);
1187 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1190 cp = _("Open newsgroup in read-only mode");
1192 cp = _("Open newsgroup");
1193 nntp_buffy (buf, sizeof (buf));
1198 if (Context && Context->path)
1199 strncpy (buf, Context->path, sizeof (buf));
1200 if (op != OP_SIDEBAR_OPEN)
1201 buffy_next (buf, sizeof (buf));
1204 if (op == OP_SIDEBAR_OPEN) {
1205 strncpy (buf, NONULL(sidebar_get_current ()), sizeof (buf));
1207 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1211 CLEARLINE (LINES - 1);
1216 if (option (OPTNEWS)) {
1217 unset_option (OPTNEWS);
1218 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1222 mutt_expand_path (buf, sizeof (buf));
1223 if (mx_get_magic (buf) <= 0) {
1224 mutt_error (_("%s is not a mailbox."), buf);
1227 str_replace (&CurrentFolder, buf);
1232 #ifdef USE_COMPRESSED
1233 if (Context->compressinfo && Context->realpath)
1234 str_replace (&LastFolder, Context->realpath);
1238 str_replace (&LastFolder, Context->path);
1239 oldcount = Context ? Context->msgcount : 0;
1241 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1242 if (check == M_NEW_MAIL || check == M_REOPENED)
1243 update_index (menu, Context, check, oldcount, index_hint);
1245 set_option (OPTSEARCHINVALID);
1246 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1249 mem_free (&Context);
1254 /* Set CurrentMenu to MENU_MAIN before executing any folder
1255 * hooks so that all the index menu functions are available to
1259 CurrentMenu = MENU_MAIN;
1260 mutt_folder_hook (buf);
1262 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1263 menu->current = ci_first_message ();
1267 sidebar_set_current (buf);
1270 /* buffy_check() must be done with mail-reader mode! */
1271 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1273 && (Context->magic ==
1274 M_NNTP)) ? IndexNewsHelp :
1277 mutt_clear_error ();
1278 buffy_check (1); /* force the buffy check after we have changed
1280 menu->redraw = REDRAW_FULL;
1281 set_option (OPTSEARCHINVALID);
1284 case OP_DISPLAY_MESSAGE:
1285 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1290 * toggle the weeding of headers so that a user can press the key
1291 * again while reading the message.
1293 if (op == OP_DISPLAY_HEADERS)
1294 toggle_option (OPTWEED);
1296 unset_option (OPTNEEDRESORT);
1298 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1299 mutt_uncollapse_thread (Context, CURHDR);
1300 mutt_set_virtual (Context);
1301 if (option (OPTUNCOLLAPSEJUMP))
1302 menu->current = mutt_thread_next_unread (Context, CURHDR);
1305 if (option (OPTPGPAUTODEC) &&
1306 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1307 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1309 if ((op = mutt_display_message (CURHDR)) == -1) {
1310 unset_option (OPTNEEDRESORT);
1314 menu->menu = MENU_PAGER;
1315 menu->oldcurrent = menu->current;
1321 if (menu->menu == MENU_MAIN && attach_msg) {
1326 if ((menu->menu == MENU_MAIN)
1327 && (query_quadoption (OPT_QUIT,
1328 _("Exit Mutt-ng without saving?")) == M_YES))
1331 mx_fastclose_mailbox (Context);
1332 mem_free (&Context);
1343 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1344 /* if we were in the pager, redisplay the message */
1345 if (menu->menu == MENU_PAGER) {
1346 op = OP_DISPLAY_MESSAGE;
1350 menu->redraw = REDRAW_CURRENT;
1353 case OP_MAIN_BREAK_THREAD:
1359 if ((Sort & SORT_MASK) != SORT_THREADS)
1360 mutt_error (_("Threading is not enabled."));
1364 HEADER *oldcur = CURHDR;
1366 mutt_break_thread (CURHDR);
1367 mutt_sort_headers (Context, 1);
1368 menu->current = oldcur->virtual;
1371 Context->changed = 1;
1372 mutt_message _("Thread broken");
1374 if (menu->menu == MENU_PAGER) {
1375 op = OP_DISPLAY_MESSAGE;
1379 menu->redraw |= REDRAW_INDEX;
1383 case OP_MAIN_LINK_THREADS:
1389 if ((Sort & SORT_MASK) != SORT_THREADS)
1390 mutt_error (_("Threading is not enabled."));
1392 else if (!CURHDR->env->message_id)
1393 mutt_error (_("No Message-ID: header available to link thread"));
1395 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1396 mutt_error (_("First, please tag a message to be linked here"));
1399 HEADER *oldcur = CURHDR;
1401 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1403 mutt_sort_headers (Context, 1);
1404 menu->current = oldcur->virtual;
1406 Context->changed = 1;
1407 mutt_message _("Threads linked");
1410 mutt_error (_("No thread linked"));
1413 if (menu->menu == MENU_PAGER) {
1414 op = OP_DISPLAY_MESSAGE;
1418 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1421 case OP_MAIN_NEXT_UNDELETED:
1425 if (menu->current >= Context->vcount - 1) {
1426 if (menu->menu == MENU_MAIN)
1427 mutt_error (_("You are on the last message."));
1431 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1432 menu->current = menu->oldcurrent;
1433 if (menu->menu == MENU_MAIN)
1434 mutt_error (_("No undeleted messages."));
1436 else if (menu->menu == MENU_PAGER) {
1437 op = OP_DISPLAY_MESSAGE;
1441 menu->redraw = REDRAW_MOTION;
1448 if (menu->current >= Context->vcount - 1) {
1449 if (menu->menu == MENU_MAIN)
1450 mutt_error (_("You are on the last message."));
1455 if (menu->menu == MENU_PAGER) {
1456 op = OP_DISPLAY_MESSAGE;
1460 menu->redraw = REDRAW_MOTION;
1463 case OP_MAIN_PREV_UNDELETED:
1467 if (menu->current < 1) {
1468 mutt_error (_("You are on the first message."));
1472 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1473 menu->current = menu->oldcurrent;
1474 if (menu->menu == MENU_MAIN)
1475 mutt_error (_("No undeleted messages."));
1477 else if (menu->menu == MENU_PAGER) {
1478 op = OP_DISPLAY_MESSAGE;
1482 menu->redraw = REDRAW_MOTION;
1489 if (menu->current < 1) {
1490 if (menu->menu == MENU_MAIN)
1491 mutt_error (_("You are on the first message."));
1496 if (menu->menu == MENU_PAGER) {
1497 op = OP_DISPLAY_MESSAGE;
1501 menu->redraw = REDRAW_MOTION;
1504 case OP_DECRYPT_COPY:
1505 case OP_DECRYPT_SAVE:
1509 case OP_COPY_MESSAGE:
1511 case OP_DECODE_COPY:
1512 case OP_DECODE_SAVE:
1515 if (mutt_save_message (tag ? NULL : CURHDR,
1516 (op == OP_DECRYPT_SAVE) ||
1517 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1518 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1519 (op == OP_DECRYPT_SAVE)
1520 || (op == OP_DECRYPT_COPY)
1521 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1528 menu->redraw |= REDRAW_INDEX;
1529 else if (option (OPTRESOLVE)) {
1530 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1531 menu->current = menu->oldcurrent;
1532 menu->redraw |= REDRAW_CURRENT;
1535 menu->redraw |= REDRAW_MOTION_RESYNCH;
1538 menu->redraw |= REDRAW_CURRENT;
1542 case OP_MAIN_NEXT_NEW:
1543 case OP_MAIN_NEXT_UNREAD:
1544 case OP_MAIN_PREV_NEW:
1545 case OP_MAIN_PREV_UNREAD:
1546 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1547 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1550 int first_unread = -1;
1558 for (j = 0; j != Context->vcount; j++) {
1559 #define CURHDRi Context->hdrs[Context->v2r[i]]
1560 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1561 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1563 if (i > Context->vcount - 1) {
1564 mutt_message _("Search wrapped to top.");
1572 mutt_message _("Search wrapped to bottom.");
1574 i = Context->vcount - 1;
1578 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1579 if (UNREAD (CURHDRi) && first_unread == -1)
1581 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1584 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1585 if (first_unread == -1)
1587 if ((!CURHDRi->old) && first_new == -1)
1591 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1594 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1595 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1596 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1601 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1602 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1603 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1605 menu->current = first_new;
1606 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1607 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1608 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1609 && first_unread != -1)
1610 menu->current = first_unread;
1612 if (menu->current == -1) {
1613 menu->current = menu->oldcurrent;
1614 mutt_error ("%s%s.",
1615 (op == OP_MAIN_NEXT_NEW
1617 OP_MAIN_PREV_NEW) ? _("No new messages") :
1618 _("No unread messages"),
1619 Context->pattern ? _(" in this limited view") : "");
1621 else if (menu->menu == MENU_PAGER) {
1622 op = OP_DISPLAY_MESSAGE;
1626 menu->redraw = REDRAW_MOTION;
1629 case OP_FLAG_MESSAGE:
1635 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1638 for (j = 0; j < Context->vcount; j++) {
1639 if (Context->hdrs[Context->v2r[j]]->tagged)
1640 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1641 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1644 menu->redraw |= REDRAW_INDEX;
1647 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1648 if (option (OPTRESOLVE)) {
1649 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1650 menu->current = menu->oldcurrent;
1651 menu->redraw = REDRAW_CURRENT;
1654 menu->redraw = REDRAW_MOTION_RESYNCH;
1657 menu->redraw = REDRAW_CURRENT;
1659 menu->redraw |= REDRAW_STATUS;
1668 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1671 for (j = 0; j < Context->vcount; j++) {
1672 if (Context->hdrs[Context->v2r[j]]->tagged) {
1673 if (Context->hdrs[Context->v2r[j]]->read ||
1674 Context->hdrs[Context->v2r[j]]->old)
1675 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1678 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1682 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1685 if (CURHDR->read || CURHDR->old)
1686 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1688 mutt_set_flag (Context, CURHDR, M_READ, 1);
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;
1700 menu->redraw |= REDRAW_STATUS;
1704 case OP_TOGGLE_WRITE:
1707 if (mx_toggle_write (Context) == 0)
1708 menu->redraw |= REDRAW_STATUS;
1711 case OP_MAIN_NEXT_THREAD:
1712 case OP_MAIN_NEXT_SUBTHREAD:
1713 case OP_MAIN_PREV_THREAD:
1714 case OP_MAIN_PREV_SUBTHREAD:
1719 case OP_MAIN_NEXT_THREAD:
1720 menu->current = mutt_next_thread (CURHDR);
1723 case OP_MAIN_NEXT_SUBTHREAD:
1724 menu->current = mutt_next_subthread (CURHDR);
1727 case OP_MAIN_PREV_THREAD:
1728 menu->current = mutt_previous_thread (CURHDR);
1731 case OP_MAIN_PREV_SUBTHREAD:
1732 menu->current = mutt_previous_subthread (CURHDR);
1736 if (menu->current < 0) {
1737 menu->current = menu->oldcurrent;
1738 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1739 mutt_error (_("No more threads."));
1742 mutt_error (_("You are on the first thread."));
1744 else if (menu->menu == MENU_PAGER) {
1745 op = OP_DISPLAY_MESSAGE;
1749 menu->redraw = REDRAW_MOTION;
1752 case OP_MAIN_PARENT_MESSAGE:
1757 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1758 menu->current = menu->oldcurrent;
1760 else if (menu->menu == MENU_PAGER) {
1761 op = OP_DISPLAY_MESSAGE;
1765 menu->redraw = REDRAW_MOTION;
1768 case OP_MAIN_SET_FLAG:
1769 case OP_MAIN_CLEAR_FLAG:
1775 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1777 menu->redraw = REDRAW_STATUS;
1779 menu->redraw |= REDRAW_INDEX;
1780 else if (option (OPTRESOLVE)) {
1781 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1782 menu->current = menu->oldcurrent;
1783 menu->redraw |= REDRAW_CURRENT;
1786 menu->redraw |= REDRAW_MOTION_RESYNCH;
1789 menu->redraw |= REDRAW_CURRENT;
1793 case OP_MAIN_COLLAPSE_THREAD:
1797 if ((Sort & SORT_MASK) != SORT_THREADS) {
1798 mutt_error (_("Threading is not enabled."));
1803 if (CURHDR->collapsed) {
1804 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1805 mutt_set_virtual (Context);
1806 if (option (OPTUNCOLLAPSEJUMP))
1807 menu->current = mutt_thread_next_unread (Context, CURHDR);
1809 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1810 menu->current = mutt_collapse_thread (Context, CURHDR);
1811 mutt_set_virtual (Context);
1814 mutt_error (_("Thread contains unread messages."));
1819 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1823 case OP_MAIN_COLLAPSE_ALL:
1827 if ((Sort & SORT_MASK) != SORT_THREADS) {
1828 mutt_error (_("Threading is not enabled."));
1835 THREAD *thread, *top;
1838 if (CURHDR->collapsed)
1839 final = mutt_uncollapse_thread (Context, CURHDR);
1840 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1841 final = mutt_collapse_thread (Context, CURHDR);
1843 final = CURHDR->virtual;
1845 base = Context->hdrs[Context->v2r[final]];
1847 top = Context->tree;
1848 Context->collapsed = !Context->collapsed;
1849 while ((thread = top) != NULL) {
1850 while (!thread->message)
1851 thread = thread->child;
1852 h = thread->message;
1854 if (h->collapsed != Context->collapsed) {
1856 mutt_uncollapse_thread (Context, h);
1857 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1858 mutt_collapse_thread (Context, h);
1863 mutt_set_virtual (Context);
1864 for (j = 0; j < Context->vcount; j++) {
1865 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1871 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1875 /* --------------------------------------------------------------------
1876 * These functions are invoked directly from the internal-pager
1879 case OP_BOUNCE_MESSAGE:
1884 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1887 case OP_CREATE_ALIAS:
1889 mutt_create_alias (Context
1890 && Context->vcount ? CURHDR->env : NULL, NULL);
1891 MAYBE_REDRAW (menu->redraw);
1892 menu->redraw |= REDRAW_CURRENT;
1897 mutt_query_menu (NULL, 0);
1898 MAYBE_REDRAW (menu->redraw);
1901 case OP_PURGE_MESSAGE:
1908 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1911 mutt_tag_set_flag (M_DELETE, 1);
1912 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1913 if (option (OPTDELETEUNTAG))
1914 mutt_tag_set_flag (M_TAG, 0);
1915 menu->redraw = REDRAW_INDEX;
1918 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1919 mutt_set_flag (Context, CURHDR, M_PURGED,
1920 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1921 if (option (OPTDELETEUNTAG))
1922 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1923 if (option (OPTRESOLVE)) {
1924 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1925 menu->current = menu->oldcurrent;
1926 menu->redraw = REDRAW_CURRENT;
1928 else if (menu->menu == MENU_PAGER) {
1929 op = OP_DISPLAY_MESSAGE;
1933 menu->redraw |= REDRAW_MOTION_RESYNCH;
1936 menu->redraw = REDRAW_CURRENT;
1938 menu->redraw |= REDRAW_STATUS;
1941 case OP_DELETE_THREAD:
1942 case OP_DELETE_SUBTHREAD:
1948 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1950 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1951 op == OP_DELETE_THREAD ? 0 : 1);
1954 if (option (OPTDELETEUNTAG))
1955 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1956 op == OP_DELETE_THREAD ? 0 : 1);
1957 if (option (OPTRESOLVE))
1958 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1959 menu->current = menu->oldcurrent;
1960 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1966 if (Context && Context->magic == M_NNTP) {
1967 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1968 ((NNTP_DATA *) Context->data)->group))
1969 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1974 case OP_DISPLAY_ADDRESS:
1978 mutt_display_address (CURHDR->env);
1981 case OP_ENTER_COMMAND:
1983 CurrentMenu = MENU_MAIN;
1984 mutt_enter_command ();
1985 mutt_check_rescore (Context);
1986 if (option (OPTFORCEREDRAWINDEX))
1987 menu->redraw = REDRAW_FULL;
1988 unset_option (OPTFORCEREDRAWINDEX);
1989 unset_option (OPTFORCEREDRAWPAGER);
1992 case OP_EDIT_MESSAGE:
1999 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
2001 if (option (OPTPGPAUTODEC)
2002 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2003 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2004 mutt_edit_message (Context, tag ? NULL : CURHDR);
2005 menu->redraw = REDRAW_FULL;
2009 case OP_FORWARD_MESSAGE:
2015 if (option (OPTPGPAUTODEC) &&
2016 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2017 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2018 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2019 menu->redraw = REDRAW_FULL;
2023 case OP_FORGET_PASSPHRASE:
2024 crypt_forget_passphrase ();
2027 case OP_GROUP_REPLY:
2033 if (option (OPTPGPAUTODEC) &&
2034 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2035 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2037 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2038 tag ? NULL : CURHDR);
2039 menu->redraw = REDRAW_FULL;
2048 if (option (OPTPGPAUTODEC) &&
2049 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2050 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2052 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2053 tag ? NULL : CURHDR);
2054 menu->redraw = REDRAW_FULL;
2060 ci_send_message (0, NULL, NULL, Context, NULL);
2061 menu->redraw = REDRAW_FULL;
2065 if (!(WithCrypto & APPLICATION_PGP))
2068 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2069 menu->redraw = REDRAW_FULL;
2073 case OP_EXTRACT_KEYS:
2078 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2079 menu->redraw = REDRAW_FULL;
2083 case OP_CHECK_TRADITIONAL:
2084 if (!(WithCrypto & APPLICATION_PGP))
2088 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2089 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2091 if (menu->menu == MENU_PAGER) {
2092 op = OP_DISPLAY_MESSAGE;
2101 mutt_pipe_message (tag ? NULL : CURHDR);
2102 MAYBE_REDRAW (menu->redraw);
2109 mutt_print_message (tag ? NULL : CURHDR);
2112 case OP_MAIN_READ_THREAD:
2113 case OP_MAIN_READ_SUBTHREAD:
2119 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2121 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2122 op == OP_MAIN_READ_THREAD ? 0 : 1);
2125 if (option (OPTRESOLVE)) {
2126 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2127 mutt_next_thread (CURHDR) :
2128 mutt_next_subthread (CURHDR))) == -1)
2129 menu->current = menu->oldcurrent;
2131 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2135 case OP_RECALL_MESSAGE:
2138 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2139 menu->redraw = REDRAW_FULL;
2149 for (j = 0; j < Context->vcount; j++) {
2150 if (Context->hdrs[Context->v2r[j]]->tagged)
2151 mutt_resend_message (NULL, Context,
2152 Context->hdrs[Context->v2r[j]]);
2156 mutt_resend_message (NULL, Context, CURHDR);
2158 menu->redraw = REDRAW_FULL;
2164 case OP_FORWARD_TO_GROUP:
2167 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2168 Context && Context->msgcount == 0) {
2169 mutt_error (_("There are no messages."));
2172 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2173 str_casecmp (CURHDR->env->followup_to, "poster") ||
2174 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2175 _("Reply by mail as poster prefers?")) !=
2177 if (Context && Context->magic == M_NNTP
2178 && !((NNTP_DATA *) Context->data)->allowed
2179 && query_quadoption (OPT_TOMODERATED,
2181 ("Posting to this group not allowed, may be moderated. Continue?"))
2185 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2188 if (op == OP_FOLLOWUP)
2189 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2190 tag ? NULL : CURHDR);
2192 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2193 tag ? NULL : CURHDR);
2195 menu->redraw = REDRAW_FULL;
2206 if (option (OPTPGPAUTODEC) &&
2207 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2208 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2210 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2211 menu->redraw = REDRAW_FULL;
2214 case OP_SHELL_ESCAPE:
2216 mutt_shell_escape ();
2217 MAYBE_REDRAW (menu->redraw);
2221 case OP_TAG_SUBTHREAD:
2225 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2226 op == OP_TAG_THREAD ? 0 : 1);
2229 if (option (OPTRESOLVE)) {
2230 menu->current = mutt_next_thread (CURHDR);
2232 if (menu->current == -1)
2233 menu->current = menu->oldcurrent;
2235 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2245 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2248 mutt_tag_set_flag (M_DELETE, 0);
2249 mutt_tag_set_flag (M_PURGED, 0);
2250 menu->redraw = REDRAW_INDEX;
2253 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2254 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2255 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2257 menu->redraw = REDRAW_MOTION_RESYNCH;
2260 menu->redraw = REDRAW_CURRENT;
2262 menu->redraw |= REDRAW_STATUS;
2265 case OP_UNDELETE_THREAD:
2266 case OP_UNDELETE_SUBTHREAD:
2272 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2274 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2275 op == OP_UNDELETE_THREAD ? 0 : 1)
2276 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2277 op == OP_UNDELETE_THREAD ? 0 : 1);
2280 if (option (OPTRESOLVE)) {
2281 if (op == OP_UNDELETE_THREAD)
2282 menu->current = mutt_next_thread (CURHDR);
2284 menu->current = mutt_next_subthread (CURHDR);
2286 if (menu->current == -1)
2287 menu->current = menu->oldcurrent;
2289 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2298 if (option (OPTFORCEBUFFYCHECK))
2301 menu->redraw = REDRAW_FULL;
2304 case OP_VIEW_ATTACHMENTS:
2307 mutt_view_attachments (CURHDR);
2308 if (CURHDR->attach_del)
2309 Context->changed = 1;
2310 menu->redraw = REDRAW_FULL;
2320 case OP_SIDEBAR_SCROLL_UP:
2321 case OP_SIDEBAR_SCROLL_DOWN:
2322 case OP_SIDEBAR_NEXT:
2323 case OP_SIDEBAR_PREV:
2324 case OP_SIDEBAR_NEXT_NEW:
2325 case OP_SIDEBAR_PREV_NEW:
2326 sidebar_scroll (op, menu->menu);
2329 if (menu->menu == MENU_MAIN)
2330 km_error_key (MENU_MAIN);
2333 if (menu->menu == MENU_PAGER) {
2334 menu->menu = MENU_MAIN;
2335 menu->redraw = REDRAW_FULL;
2337 set_option (OPTWEED); /* turn header weeding back on. */
2346 /* Close all open IMAP connections */
2351 /* Close all open NNTP connections */
2356 mutt_menuDestroy (&menu);
2360 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2367 for (color = ColorIndexList; color; color = color->next)
2368 if (mutt_pattern_exec
2369 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2370 curhdr->pair = color->pair;
2373 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];