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.
17 #include <lib-lib/mem.h>
18 #include <lib-lib/str.h>
19 #include <lib-lib/macros.h>
22 #include "mutt_curses.h"
24 #include "mutt_menu.h"
27 #include "recvattach.h"
39 #include "imap_private.h"
42 #include "mutt_crypt.h"
49 #include "mutt_sasl.h"
52 #include "lib/debug.h"
62 static const char *No_mailbox_is_open = N_("No mailbox is open.");
63 static const char *There_are_no_messages = N_("There are no messages.");
64 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
65 static const char *Function_not_permitted_in_attach_message_mode =
66 N_("Function not permitted in attach-message mode.");
67 static const char *No_visible = N_("No visible messages.");
69 #define CHECK_IN_MAILBOX if (!Context) \
72 mutt_error (_(No_mailbox_is_open)); \
76 #define CHECK_MSGCOUNT if (!Context) \
79 mutt_error(_(No_mailbox_is_open)); \
82 else if (!Context->msgcount) \
85 mutt_error(_(There_are_no_messages)); \
89 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
92 mutt_error(_(No_visible)); \
97 #define CHECK_READONLY if (Context->readonly) \
100 mutt_error(_(Mailbox_is_read_only)); \
104 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
107 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
111 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
112 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
113 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
114 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
116 extern const char *ReleaseDate;
117 extern size_t UngetCount;
119 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
122 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
123 int edgemsgno, reverse = Sort & SORT_REVERSE;
124 HEADER *h = Context->hdrs[Context->v2r[num]];
127 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
128 flag |= M_FORMAT_TREE; /* display the thread tree */
129 if (h->display_subject)
130 flag |= M_FORMAT_FORCESUBJ;
133 if (menu->top + menu->pagelen > menu->max)
134 edgemsgno = Context->v2r[menu->max - 1];
136 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
139 edgemsgno = Context->v2r[menu->top];
141 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
145 /* if no ancestor is visible on current screen, provisionally force
147 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
149 flag |= M_FORMAT_FORCESUBJ;
152 else if (tmp->message->virtual >= 0)
155 if (flag & M_FORMAT_FORCESUBJ) {
156 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
160 /* ...but if a previous sibling is available, don't force it */
161 if (reverse ? tmp->message->msgno >
162 edgemsgno : tmp->message->msgno < edgemsgno)
164 else if (tmp->message->virtual >= 0) {
165 flag &= ~M_FORMAT_FORCESUBJ;
173 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
176 int index_color (int index_no)
178 HEADER *h = Context->hdrs[Context->v2r[index_no]];
183 mutt_set_header_color (Context, h);
187 static int ci_next_undeleted (int msgno)
191 for (i = msgno + 1; i < Context->vcount; i++)
192 if (!Context->hdrs[Context->v2r[i]]->deleted)
197 static int ci_previous_undeleted (int msgno)
201 for (i = msgno - 1; i >= 0; i--)
202 if (!Context->hdrs[Context->v2r[i]]->deleted)
207 /* Return the index of the first new message, or failing that, the first
210 static int ci_first_message (void)
214 if (Context && Context->msgcount) {
215 for (i = 0; i < Context->vcount; i++) {
216 if (!Context->hdrs[Context->v2r[i]]->read &&
217 !Context->hdrs[Context->v2r[i]]->deleted) {
218 if (!Context->hdrs[Context->v2r[i]]->old)
227 /* If Sort is reverse and not threaded, the latest message is first.
228 * If Sort is threaded, the latest message is first iff exactly one
229 * of Sort and SortAux are reverse.
231 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
232 ((Sort & SORT_MASK) == SORT_THREADS &&
233 ((Sort ^ SortAux) & SORT_REVERSE)))
236 return (Context->vcount ? Context->vcount - 1 : 0);
241 /* This should be in mx.c, but it only gets used here. */
242 static int mx_toggle_write (CONTEXT * ctx)
248 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
253 if (ctx->dontwrite) {
255 mutt_message (_("Changes to folder will be written on folder exit."));
259 mutt_message (_("Changes to folder will not be written."));
265 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
266 int oldcount, int index_hint)
268 /* store pointers to the newly added messages */
269 HEADER **save_new = NULL;
272 /* take note of the current message */
274 if (menu->current < Context->vcount)
275 menu->oldcurrent = index_hint;
277 oldcount = 0; /* invalid message number! */
280 /* We are in a limited view. Check if the new message(s) satisfy
281 * the limit criteria. If they do, set their virtual msgno so that
282 * they will be visible in the limited view */
283 if (Context->pattern) {
284 #define THIS_BODY Context->hdrs[j]->content
285 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
286 if (mutt_pattern_exec
287 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
289 Context->hdrs[j]->virtual = Context->vcount;
290 Context->v2r[Context->vcount] = j;
291 Context->hdrs[j]->limited = 1;
294 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
300 /* save the list of new messages */
301 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
302 save_new = p_new(HEADER*, Context->msgcount - oldcount);
303 for (j = oldcount; j < Context->msgcount; j++)
304 save_new[j - oldcount] = Context->hdrs[j];
307 /* if the mailbox was reopened, need to rethread from scratch */
308 mutt_sort_headers (Context, (check == M_REOPENED));
310 /* uncollapse threads with new mail */
311 if ((Sort & SORT_MASK) == SORT_THREADS) {
312 if (check == M_REOPENED) {
315 Context->collapsed = 0;
317 for (h = Context->tree; h; h = h->next) {
318 for (j = h; !j->message; j = j->child);
319 mutt_uncollapse_thread (Context, j->message);
321 mutt_set_virtual (Context);
324 for (j = 0; j < Context->msgcount - oldcount; j++) {
327 for (k = 0; k < Context->msgcount; k++) {
328 HEADER *h = Context->hdrs[k];
330 if (h == save_new[j] && (!Context->pattern || h->limited))
331 mutt_uncollapse_thread (Context, h);
335 mutt_set_virtual (Context);
341 /* restore the current message to the message it was pointing to */
342 for (j = 0; j < Context->vcount; j++) {
343 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
350 if (menu->current < 0)
351 menu->current = ci_first_message ();
354 static void resort_index (MUTTMENU * menu)
357 HEADER *current = CURHDR;
360 mutt_sort_headers (Context, 0);
361 /* Restore the current message */
363 for (i = 0; i < Context->vcount; i++) {
364 if (Context->hdrs[Context->v2r[i]] == current) {
370 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
371 menu->current = mutt_parent_message (Context, current);
373 if (menu->current < 0)
374 menu->current = ci_first_message ();
376 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
379 struct mapping_t IndexHelp[] = {
380 {N_("Quit"), OP_QUIT},
381 {N_("Del"), OP_DELETE},
382 {N_("Undel"), OP_UNDELETE},
383 {N_("Save"), OP_SAVE},
384 {N_("Mail"), OP_MAIL},
385 {N_("Reply"), OP_REPLY},
386 {N_("Group"), OP_GROUP_REPLY},
387 {N_("Help"), OP_HELP},
392 struct mapping_t IndexNewsHelp[] = {
393 {N_("Quit"), OP_QUIT},
394 {N_("Del"), OP_DELETE},
395 {N_("Undel"), OP_UNDELETE},
396 {N_("Save"), OP_SAVE},
397 {N_("Post"), OP_POST},
398 {N_("Followup"), OP_FOLLOWUP},
399 {N_("Catchup"), OP_CATCHUP},
400 {N_("Help"), OP_HELP},
405 /* This function handles the message index window as well as commands returned
406 * from the pager (MENU_PAGER).
408 int mutt_index_menu (void)
410 char buf[LONG_STRING], helpstr[SHORT_STRING];
413 int done = 0; /* controls when to exit the "event" loop */
415 int tag = 0; /* has the tag-prefix command been pressed? */
420 char *cp; /* temporary variable. */
421 int index_hint; /* used to restore cursor position */
422 int do_buffy_notify = 1;
423 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
424 int attach_msg = option (OPTATTACHMSG);
426 menu = mutt_new_menu ();
427 menu->menu = MENU_MAIN;
429 menu->pagelen = LINES - 3;
430 menu->make_entry = index_make_entry;
431 menu->color = index_color;
432 menu->current = ci_first_message ();
433 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
436 && (Context->magic ==
437 M_NNTP)) ? IndexNewsHelp :
442 buffy_check (1); /* force the buffy check after we enter the folder */
443 /* record folder we open to place sidebar indicator properly */
444 if (Context && Context->path)
445 sidebar_set_current (Context->path);
449 tag = 0; /* clear the tag-prefix */
451 menu->max = Context ? Context->vcount : 0;
452 oldcount = Context ? Context->msgcount : 0;
454 /* check if we need to resort the index because just about
455 * any 'op' below could do mutt_enter_command(), either here or
456 * from any new menu launched, and change $sort/$sort_aux
458 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
461 if (option (OPTREDRAWTREE) && Context && Context->msgcount
462 && (Sort & SORT_MASK) == SORT_THREADS) {
463 mutt_draw_tree (Context);
464 menu->redraw |= REDRAW_STATUS;
465 unset_option (OPTREDRAWTREE);
468 if (Context && !attach_msg) {
471 /* check for new mail in the mailbox. If nonzero, then something has
472 * changed about the file (either we got new mail or the file was
473 * modified underneath us.)
477 imap_allow_reopen (Context);
480 index_hint = (Context->vcount && menu->current >= 0
481 && menu->current < Context->vcount) ? CURHDR->index : 0;
483 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
484 if (!Context->path) {
485 /* fatal error occurred */
487 menu->redraw = REDRAW_FULL;
489 set_option (OPTSEARCHINVALID);
491 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
492 update_index (menu, Context, check, oldcount, index_hint);
494 /* notify the user of new mail */
495 if (check == M_REOPENED)
497 ("Mailbox was externally modified. Flags may be wrong."));
498 else if (check == M_NEW_MAIL) {
499 /* on new mail: redraw sidebar */
500 sidebar_draw (CurrentMenu);
501 mutt_message (_("New mail in this mailbox."));
503 if (option (OPTBEEPNEW))
506 else if (check == M_FLAGS)
507 mutt_message (_("Mailbox was externally modified."));
509 /* avoid the message being overwritten by buffy */
512 menu->redraw = REDRAW_FULL;
513 menu->max = Context->vcount;
515 set_option (OPTSEARCHINVALID);
521 imap_disallow_reopen (Context);
525 /* check for new mail in the incoming folders */
527 if ((newcount = buffy_check (0)) != oldcount) {
528 menu->redraw |= REDRAW_STATUS;
529 menu->redraw |= REDRAW_SIDEBAR;
531 if (do_buffy_notify) {
532 if (buffy_notify () && option (OPTBEEPNEW))
541 if (menu->redraw & REDRAW_SIDEBAR)
542 sidebar_draw (menu->menu);
543 if (menu->redraw & REDRAW_FULL) {
544 menu_redraw_full (menu);
545 sidebar_draw (menu->menu);
549 if (menu->menu == MENU_MAIN) {
550 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
551 menu_check_recenter (menu);
553 if (menu->redraw & REDRAW_INDEX) {
554 menu_redraw_index (menu);
555 menu->redraw |= REDRAW_STATUS;
557 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
558 menu_redraw_motion (menu);
559 else if (menu->redraw & REDRAW_CURRENT)
560 menu_redraw_current (menu);
563 if (menu->redraw & REDRAW_STATUS) {
564 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
565 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
566 sidebar_draw_frames();
567 SETCOLOR (MT_COLOR_STATUS);
568 BKGDSET (MT_COLOR_STATUS);
569 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
570 mutt_paddstr (COLS-SW, buf);
571 SETCOLOR (MT_COLOR_NORMAL);
572 BKGDSET (MT_COLOR_NORMAL);
573 sidebar_set_buffystats (Context);
574 menu->redraw &= ~REDRAW_STATUS;
575 if (option (OPTXTERMSETTITLES)) {
576 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
577 mutt_xterm_set_title (buf);
578 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
579 mutt_xterm_set_icon (buf);
584 if (menu->current < menu->max)
585 menu->oldcurrent = menu->current;
587 menu->oldcurrent = -1;
589 if (option (OPTARROWCURSOR))
590 move (menu->current - menu->top + menu->offset, 2);
591 else if (option (OPTBRAILLEFRIENDLY))
592 move (menu->current - menu->top + menu->offset, 0);
594 move (menu->current - menu->top + menu->offset, COLS - 1);
597 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
600 mutt_resize_screen ();
601 menu->redraw = REDRAW_FULL;
602 menu->menu = MENU_MAIN;
604 menu->top = 0; /* so we scroll the right amount */
606 * force a real complete redraw. clrtobot() doesn't seem to be able
607 * to handle every case without this.
609 clearok (stdscr, TRUE);
614 op = km_dokey (MENU_MAIN);
616 debug_print (4, ("Got op %d\n", op));
619 continue; /* either user abort or timeout */
623 /* special handling for the tag-prefix function */
624 if (op == OP_TAG_PREFIX) {
626 mutt_error (_("No mailbox is open."));
631 if (!Context->tagged) {
632 mutt_error (_("No tagged messages."));
638 /* give visual indication that the next command is a tag- command */
639 mvaddstr (LINES - 1, 0, "tag-");
642 /* get the real command */
643 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
644 /* abort tag sequence */
645 CLEARLINE (LINES - 1);
649 else if (option (OPTAUTOTAG) && Context && Context->tagged)
652 if (op == OP_TAG_PREFIX_COND) {
654 mutt_error (_("No mailbox is open."));
659 if (!Context->tagged) {
662 while (UngetCount > 0) {
664 if (tmp.op == OP_END_COND)
667 mutt_message (_("Nothing to do."));
673 /* give visual indication that the next command is a tag- command */
674 mvaddstr (LINES - 1, 0, "tag-");
677 /* get the real command */
678 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
679 /* abort tag sequence */
680 CLEARLINE (LINES - 1);
688 if (menu->current < menu->max)
689 menu->oldcurrent = menu->current;
691 menu->oldcurrent = -1;
693 mutt_curs_set (1); /* fallback from the pager */
697 unset_option (OPTNEWS); /* for any case */
702 /* ----------------------------------------------------------------------
707 menu_bottom_page (menu);
710 menu_first_entry (menu);
713 menu_middle_page (menu);
719 menu_half_down (menu);
722 menu_next_line (menu);
725 menu_prev_line (menu);
728 menu_next_page (menu);
731 menu_prev_page (menu);
734 menu_last_entry (menu);
737 menu_top_page (menu);
740 menu_current_top (menu);
742 case OP_CURRENT_MIDDLE:
743 menu_current_middle (menu);
745 case OP_CURRENT_BOTTOM:
746 menu_current_bottom (menu);
753 if (Context->magic == M_NNTP) {
756 if (op == OP_GET_MESSAGE) {
758 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
763 LIST *ref = CURHDR->env->references;
766 mutt_error (_("Article has no parent reference!"));
770 strfcpy (buf, ref->data, sizeof (buf));
772 if (!Context->id_hash)
773 Context->id_hash = mutt_make_id_hash (Context);
774 if ((h = hash_find (Context->id_hash, buf))) {
775 if (h->virtual != -1) {
776 menu->current = h->virtual;
777 menu->redraw = REDRAW_MOTION_RESYNCH;
779 else if (h->collapsed) {
780 mutt_uncollapse_thread (Context, h);
781 mutt_set_virtual (Context);
782 menu->current = h->virtual;
783 menu->redraw = REDRAW_MOTION_RESYNCH;
786 mutt_error (_("Message not visible in limited view."));
789 if (nntp_check_msgid (Context, buf) == 0) {
790 h = Context->hdrs[Context->msgcount - 1];
791 mutt_sort_headers (Context, 0);
792 menu->current = h->virtual;
793 menu->redraw = REDRAW_FULL;
796 mutt_error (_("Article %s not found on server"), buf);
801 case OP_GET_CHILDREN:
802 case OP_RECONSTRUCT_THREAD:
804 if (Context->magic == M_NNTP) {
806 int old = CURHDR->index, i;
808 if (!CURHDR->env->message_id) {
809 mutt_error (_("No Message-ID. Unable to perform operation"));
814 if (!Context->id_hash)
815 Context->id_hash = mutt_make_id_hash (Context);
816 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
818 if (op == OP_RECONSTRUCT_THREAD) {
819 LIST *ref = CURHDR->env->references;
822 nntp_check_msgid (Context, ref->data);
823 /* the last msgid in References is the root message */
825 strfcpy (buf, ref->data, sizeof (buf));
829 mutt_message (_("Check for children of message..."));
831 if (nntp_check_children (Context, buf) == 0) {
832 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
833 h = hash_find (Context->id_hash, buf);
834 /* if the root message was retrieved, move to it */
836 menu->current = h->virtual;
837 else /* try to restore old position */
838 for (i = 0; i < Context->msgcount; i++)
839 if (Context->hdrs[i]->index == old) {
840 menu->current = Context->hdrs[i]->virtual;
841 /* As an added courtesy, recenter the menu
842 * with the current entry at the middle of the screen */
843 menu_check_recenter (menu);
844 menu_current_middle (menu);
847 menu->redraw = REDRAW_FULL;
857 if (isdigit (LastKey))
858 mutt_ungetch (LastKey, 0);
860 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
864 if (!isdigit ((unsigned char) buf[0])) {
865 mutt_error (_("Argument must be a message number."));
871 if (i > 0 && i <= Context->msgcount) {
872 for (j = i - 1; j < Context->msgcount; j++) {
873 if (Context->hdrs[j]->virtual != -1)
876 if (j >= Context->msgcount) {
877 for (j = i - 2; j >= 0; j--) {
878 if (Context->hdrs[j]->virtual != -1)
884 menu->current = Context->hdrs[j]->virtual;
885 if (menu->menu == MENU_PAGER) {
886 op = OP_DISPLAY_MESSAGE;
890 menu->redraw = REDRAW_MOTION;
893 mutt_error (_("That message is not visible."));
896 mutt_error (_("Invalid message number."));
900 /* --------------------------------------------------------------------
901 * `index' specific commands
904 case OP_MAIN_DELETE_PATTERN:
910 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
913 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
914 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
918 case OP_MAIN_FETCH_MAIL:
922 menu->redraw = REDRAW_FULL;
928 mutt_help (MENU_MAIN);
929 menu->redraw = REDRAW_FULL;
932 case OP_MAIN_SHOW_LIMIT:
934 if (!Context->pattern)
935 mutt_message (_("No limit pattern is in effect."));
940 /* i18n: ask for a limit to apply */
941 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
942 mutt_message ("%s", buf);
950 menu->oldcurrent = (Context->vcount && menu->current >= 0
952 Context->vcount) ? CURHDR->index : -1;
953 if (op == OP_TOGGLE_READ) {
954 char buf[LONG_STRING];
956 if (!Context->pattern
957 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
958 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
959 Context->pattern ? Context->pattern : ".*");
960 set_option (OPTHIDEREAD);
963 strfcpy (buf, Context->pattern + 8, sizeof (buf));
964 if (!*buf || strncmp (buf, ".*", 2) == 0)
965 snprintf (buf, sizeof (buf), "~A");
966 unset_option (OPTHIDEREAD);
968 p_delete(&Context->pattern);
969 Context->pattern = m_strdup(buf);
971 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
972 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
974 if (menu->oldcurrent >= 0) {
975 /* try to find what used to be the current message */
977 for (i = 0; i < Context->vcount; i++)
978 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
982 if (menu->current < 0)
987 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
988 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
989 mutt_draw_tree (Context);
990 menu->redraw = REDRAW_FULL;
992 if (Context->pattern)
993 mutt_message _("To view all messages, limit to \"all\".");
1004 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1007 oldcount = Context ? Context->msgcount : 0;
1010 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1013 if (check == M_NEW_MAIL || check == M_REOPENED)
1014 update_index (menu, Context, check, oldcount, index_hint);
1016 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1017 set_option (OPTSEARCHINVALID);
1024 clearok (stdscr, TRUE);
1025 menu->redraw = REDRAW_FULL;
1029 case OP_SEARCH_REVERSE:
1030 case OP_SEARCH_NEXT:
1031 case OP_SEARCH_OPPOSITE:
1035 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1036 menu->current = menu->oldcurrent;
1038 menu->redraw = REDRAW_MOTION;
1042 case OP_SORT_REVERSE:
1044 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1045 if (Context && Context->msgcount) {
1046 resort_index (menu);
1047 set_option (OPTSEARCHINVALID);
1056 if (tag && !option (OPTAUTOTAG)) {
1057 for (j = 0; j < Context->vcount; j++)
1058 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1059 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1062 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1063 Context->last_tag = CURHDR->tagged ? CURHDR :
1064 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1065 ? NULL : Context->last_tag);
1066 menu->redraw = REDRAW_STATUS;
1067 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1069 menu->redraw |= REDRAW_MOTION_RESYNCH;
1072 menu->redraw |= REDRAW_CURRENT;
1076 case OP_MAIN_TAG_PATTERN:
1080 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1081 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1084 case OP_MAIN_UNDELETE_PATTERN:
1090 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1092 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1094 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1097 case OP_MAIN_UNTAG_PATTERN:
1101 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1102 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1105 /* --------------------------------------------------------------------
1106 * The following operations can be performed inside of the pager.
1110 case OP_MAIN_IMAP_FETCH:
1111 if (Context->magic == M_IMAP)
1112 imap_check_mailbox (Context, &index_hint, 1);
1116 case OP_MAIN_SYNC_FOLDER:
1118 if (Context && !Context->msgcount)
1125 int oldvcount = Context->vcount;
1126 int oldcount = Context->msgcount;
1130 /* calculate the number of messages _above_ the cursor,
1131 * so we can keep the cursor on the current message
1133 for (j = 0; j <= menu->current; j++) {
1134 if (Context->hdrs[Context->v2r[j]]->deleted)
1138 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1139 if (Context->vcount != oldvcount)
1140 menu->current -= dcount;
1141 set_option (OPTSEARCHINVALID);
1143 else if (check == M_NEW_MAIL || check == M_REOPENED)
1144 update_index (menu, Context, check, oldcount, index_hint);
1147 * do a sanity check even if mx_sync_mailbox failed.
1150 if (menu->current < 0 || menu->current >= Context->vcount)
1151 menu->current = ci_first_message ();
1154 /* check for a fatal error, or all messages deleted */
1158 /* if we were in the pager, redisplay the message */
1159 if (menu->menu == MENU_PAGER) {
1160 op = OP_DISPLAY_MESSAGE;
1164 menu->redraw = REDRAW_FULL;
1167 case OP_SIDEBAR_OPEN:
1168 case OP_MAIN_CHANGE_FOLDER:
1169 case OP_MAIN_CHANGE_FOLDER_READONLY:
1171 case OP_MAIN_CHANGE_GROUP:
1172 case OP_MAIN_CHANGE_GROUP_READONLY:
1174 if (attach_msg || option (OPTREADONLY) ||
1176 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1178 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1184 cp = _("Open mailbox in read-only mode");
1186 cp = _("Open mailbox");
1190 unset_option (OPTNEWS);
1191 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1192 set_option (OPTNEWS);
1193 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1196 cp = _("Open newsgroup in read-only mode");
1198 cp = _("Open newsgroup");
1199 nntp_buffy (buf, sizeof (buf));
1204 if (Context && Context->path)
1205 m_strcpy(buf, sizeof(buf), Context->path);
1206 if (op != OP_SIDEBAR_OPEN)
1207 buffy_next (buf, sizeof (buf));
1210 if (op == OP_SIDEBAR_OPEN) {
1211 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1213 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1214 if (menu->menu == MENU_PAGER) {
1215 op = OP_DISPLAY_MESSAGE;
1221 CLEARLINE (LINES - 1);
1226 if (option (OPTNEWS)) {
1227 unset_option (OPTNEWS);
1228 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1232 mutt_expand_path (buf, sizeof (buf));
1233 if (mx_get_magic (buf) <= 0) {
1234 mutt_error (_("%s is not a mailbox."), buf);
1237 str_replace (&CurrentFolder, buf);
1242 #ifdef USE_COMPRESSED
1243 if (Context->compressinfo && Context->realpath)
1244 str_replace (&LastFolder, Context->realpath);
1248 str_replace (&LastFolder, Context->path);
1249 oldcount = Context ? Context->msgcount : 0;
1251 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1252 if (check == M_NEW_MAIL || check == M_REOPENED)
1253 update_index (menu, Context, check, oldcount, index_hint);
1255 set_option (OPTSEARCHINVALID);
1256 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1264 /* Set CurrentMenu to MENU_MAIN before executing any folder
1265 * hooks so that all the index menu functions are available to
1269 CurrentMenu = MENU_MAIN;
1270 mutt_folder_hook (buf);
1272 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1273 menu->current = ci_first_message ();
1277 sidebar_set_current (buf);
1280 /* buffy_check() must be done with mail-reader mode! */
1281 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1283 && (Context->magic ==
1284 M_NNTP)) ? IndexNewsHelp :
1287 mutt_clear_error ();
1288 buffy_check (1); /* force the buffy check after we have changed
1290 menu->redraw = REDRAW_FULL;
1291 set_option (OPTSEARCHINVALID);
1294 case OP_DISPLAY_MESSAGE:
1295 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1300 * toggle the weeding of headers so that a user can press the key
1301 * again while reading the message.
1303 if (op == OP_DISPLAY_HEADERS)
1304 toggle_option (OPTWEED);
1306 unset_option (OPTNEEDRESORT);
1308 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1309 mutt_uncollapse_thread (Context, CURHDR);
1310 mutt_set_virtual (Context);
1311 if (option (OPTUNCOLLAPSEJUMP))
1312 menu->current = mutt_thread_next_unread (Context, CURHDR);
1315 if (option (OPTPGPAUTODEC) &&
1316 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1317 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1319 if ((op = mutt_display_message (CURHDR)) == -1) {
1320 unset_option (OPTNEEDRESORT);
1324 menu->menu = MENU_PAGER;
1325 menu->oldcurrent = menu->current;
1331 if (menu->menu == MENU_MAIN && attach_msg) {
1336 if ((menu->menu == MENU_MAIN)
1337 && (query_quadoption (OPT_QUIT,
1338 _("Exit Mutt-ng without saving?")) == M_YES))
1341 mx_fastclose_mailbox (Context);
1353 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1354 /* if we were in the pager, redisplay the message */
1355 if (menu->menu == MENU_PAGER) {
1356 op = OP_DISPLAY_MESSAGE;
1360 menu->redraw = REDRAW_CURRENT;
1363 case OP_MAIN_BREAK_THREAD:
1369 if ((Sort & SORT_MASK) != SORT_THREADS)
1370 mutt_error (_("Threading is not enabled."));
1374 HEADER *oldcur = CURHDR;
1376 mutt_break_thread (CURHDR);
1377 mutt_sort_headers (Context, 1);
1378 menu->current = oldcur->virtual;
1381 Context->changed = 1;
1382 mutt_message _("Thread broken");
1384 if (menu->menu == MENU_PAGER) {
1385 op = OP_DISPLAY_MESSAGE;
1389 menu->redraw |= REDRAW_INDEX;
1393 case OP_MAIN_LINK_THREADS:
1399 if ((Sort & SORT_MASK) != SORT_THREADS)
1400 mutt_error (_("Threading is not enabled."));
1402 else if (!CURHDR->env->message_id)
1403 mutt_error (_("No Message-ID: header available to link thread"));
1405 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1406 mutt_error (_("First, please tag a message to be linked here"));
1409 HEADER *oldcur = CURHDR;
1411 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1413 mutt_sort_headers (Context, 1);
1414 menu->current = oldcur->virtual;
1416 Context->changed = 1;
1417 mutt_message _("Threads linked");
1420 mutt_error (_("No thread linked"));
1423 if (menu->menu == MENU_PAGER) {
1424 op = OP_DISPLAY_MESSAGE;
1428 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1431 case OP_MAIN_NEXT_UNDELETED:
1435 if (menu->current >= Context->vcount - 1) {
1436 if (menu->menu == MENU_MAIN)
1437 mutt_error (_("You are on the last message."));
1441 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1442 menu->current = menu->oldcurrent;
1443 if (menu->menu == MENU_MAIN)
1444 mutt_error (_("No undeleted messages."));
1446 else if (menu->menu == MENU_PAGER) {
1447 op = OP_DISPLAY_MESSAGE;
1451 menu->redraw = REDRAW_MOTION;
1458 if (menu->current >= Context->vcount - 1) {
1459 if (menu->menu == MENU_MAIN)
1460 mutt_error (_("You are on the last message."));
1465 if (menu->menu == MENU_PAGER) {
1466 op = OP_DISPLAY_MESSAGE;
1470 menu->redraw = REDRAW_MOTION;
1473 case OP_MAIN_PREV_UNDELETED:
1477 if (menu->current < 1) {
1478 mutt_error (_("You are on the first message."));
1482 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1483 menu->current = menu->oldcurrent;
1484 if (menu->menu == MENU_MAIN)
1485 mutt_error (_("No undeleted messages."));
1487 else if (menu->menu == MENU_PAGER) {
1488 op = OP_DISPLAY_MESSAGE;
1492 menu->redraw = REDRAW_MOTION;
1499 if (menu->current < 1) {
1500 if (menu->menu == MENU_MAIN)
1501 mutt_error (_("You are on the first message."));
1506 if (menu->menu == MENU_PAGER) {
1507 op = OP_DISPLAY_MESSAGE;
1511 menu->redraw = REDRAW_MOTION;
1514 case OP_DECRYPT_COPY:
1515 case OP_DECRYPT_SAVE:
1519 case OP_COPY_MESSAGE:
1521 case OP_DECODE_COPY:
1522 case OP_DECODE_SAVE:
1525 if (mutt_save_message (tag ? NULL : CURHDR,
1526 (op == OP_DECRYPT_SAVE) ||
1527 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1528 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1529 (op == OP_DECRYPT_SAVE)
1530 || (op == OP_DECRYPT_COPY)
1531 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1538 menu->redraw |= REDRAW_INDEX;
1539 else if (option (OPTRESOLVE)) {
1540 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1541 menu->current = menu->oldcurrent;
1542 menu->redraw |= REDRAW_CURRENT;
1545 menu->redraw |= REDRAW_MOTION_RESYNCH;
1548 menu->redraw |= REDRAW_CURRENT;
1552 case OP_MAIN_NEXT_NEW:
1553 case OP_MAIN_NEXT_UNREAD:
1554 case OP_MAIN_PREV_NEW:
1555 case OP_MAIN_PREV_UNREAD:
1556 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1557 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1560 int first_unread = -1;
1568 for (j = 0; j != Context->vcount; j++) {
1569 #define CURHDRi Context->hdrs[Context->v2r[i]]
1570 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1571 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1573 if (i > Context->vcount - 1) {
1574 mutt_message _("Search wrapped to top.");
1582 mutt_message _("Search wrapped to bottom.");
1584 i = Context->vcount - 1;
1588 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1589 if (UNREAD (CURHDRi) && first_unread == -1)
1591 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1594 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1595 if (first_unread == -1)
1597 if ((!CURHDRi->old) && first_new == -1)
1601 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1604 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1605 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1606 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1611 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1612 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1613 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1615 menu->current = first_new;
1616 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1617 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1618 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1619 && first_unread != -1)
1620 menu->current = first_unread;
1622 if (menu->current == -1) {
1623 menu->current = menu->oldcurrent;
1624 mutt_error ("%s%s.",
1625 (op == OP_MAIN_NEXT_NEW
1627 OP_MAIN_PREV_NEW) ? _("No new messages") :
1628 _("No unread messages"),
1629 Context->pattern ? _(" in this limited view") : "");
1631 else if (menu->menu == MENU_PAGER) {
1632 op = OP_DISPLAY_MESSAGE;
1636 menu->redraw = REDRAW_MOTION;
1639 case OP_FLAG_MESSAGE:
1645 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1648 for (j = 0; j < Context->vcount; j++) {
1649 if (Context->hdrs[Context->v2r[j]]->tagged)
1650 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1651 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1654 menu->redraw |= REDRAW_INDEX;
1657 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1658 if (option (OPTRESOLVE)) {
1659 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1660 menu->current = menu->oldcurrent;
1661 menu->redraw = REDRAW_CURRENT;
1664 menu->redraw = REDRAW_MOTION_RESYNCH;
1667 menu->redraw = REDRAW_CURRENT;
1669 menu->redraw |= REDRAW_STATUS;
1678 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1681 for (j = 0; j < Context->vcount; j++) {
1682 if (Context->hdrs[Context->v2r[j]]->tagged) {
1683 if (Context->hdrs[Context->v2r[j]]->read ||
1684 Context->hdrs[Context->v2r[j]]->old)
1685 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1688 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1692 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1695 if (CURHDR->read || CURHDR->old)
1696 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1698 mutt_set_flag (Context, CURHDR, M_READ, 1);
1700 if (option (OPTRESOLVE)) {
1701 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1702 menu->current = menu->oldcurrent;
1703 menu->redraw = REDRAW_CURRENT;
1706 menu->redraw = REDRAW_MOTION_RESYNCH;
1709 menu->redraw = REDRAW_CURRENT;
1710 menu->redraw |= REDRAW_STATUS;
1714 case OP_TOGGLE_WRITE:
1717 if (mx_toggle_write (Context) == 0)
1718 menu->redraw |= REDRAW_STATUS;
1721 case OP_MAIN_NEXT_THREAD:
1722 case OP_MAIN_NEXT_SUBTHREAD:
1723 case OP_MAIN_PREV_THREAD:
1724 case OP_MAIN_PREV_SUBTHREAD:
1729 case OP_MAIN_NEXT_THREAD:
1730 menu->current = mutt_next_thread (CURHDR);
1733 case OP_MAIN_NEXT_SUBTHREAD:
1734 menu->current = mutt_next_subthread (CURHDR);
1737 case OP_MAIN_PREV_THREAD:
1738 menu->current = mutt_previous_thread (CURHDR);
1741 case OP_MAIN_PREV_SUBTHREAD:
1742 menu->current = mutt_previous_subthread (CURHDR);
1746 if (menu->current < 0) {
1747 menu->current = menu->oldcurrent;
1748 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1749 mutt_error (_("No more threads."));
1752 mutt_error (_("You are on the first thread."));
1754 else if (menu->menu == MENU_PAGER) {
1755 op = OP_DISPLAY_MESSAGE;
1759 menu->redraw = REDRAW_MOTION;
1762 case OP_MAIN_PARENT_MESSAGE:
1767 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1768 menu->current = menu->oldcurrent;
1770 else if (menu->menu == MENU_PAGER) {
1771 op = OP_DISPLAY_MESSAGE;
1775 menu->redraw = REDRAW_MOTION;
1778 case OP_MAIN_SET_FLAG:
1779 case OP_MAIN_CLEAR_FLAG:
1785 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1787 menu->redraw = REDRAW_STATUS;
1789 menu->redraw |= REDRAW_INDEX;
1790 else if (option (OPTRESOLVE)) {
1791 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1792 menu->current = menu->oldcurrent;
1793 menu->redraw |= REDRAW_CURRENT;
1796 menu->redraw |= REDRAW_MOTION_RESYNCH;
1799 menu->redraw |= REDRAW_CURRENT;
1803 case OP_MAIN_COLLAPSE_THREAD:
1807 if ((Sort & SORT_MASK) != SORT_THREADS) {
1808 mutt_error (_("Threading is not enabled."));
1813 if (CURHDR->collapsed) {
1814 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1815 mutt_set_virtual (Context);
1816 if (option (OPTUNCOLLAPSEJUMP))
1817 menu->current = mutt_thread_next_unread (Context, CURHDR);
1819 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1820 menu->current = mutt_collapse_thread (Context, CURHDR);
1821 mutt_set_virtual (Context);
1824 mutt_error (_("Thread contains unread messages."));
1829 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1833 case OP_MAIN_COLLAPSE_ALL:
1837 if ((Sort & SORT_MASK) != SORT_THREADS) {
1838 mutt_error (_("Threading is not enabled."));
1845 THREAD *thread, *top;
1848 if (CURHDR->collapsed)
1849 final = mutt_uncollapse_thread (Context, CURHDR);
1850 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1851 final = mutt_collapse_thread (Context, CURHDR);
1853 final = CURHDR->virtual;
1855 base = Context->hdrs[Context->v2r[final]];
1857 top = Context->tree;
1858 Context->collapsed = !Context->collapsed;
1859 while ((thread = top) != NULL) {
1860 while (!thread->message)
1861 thread = thread->child;
1862 h = thread->message;
1864 if (h->collapsed != Context->collapsed) {
1866 mutt_uncollapse_thread (Context, h);
1867 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1868 mutt_collapse_thread (Context, h);
1873 mutt_set_virtual (Context);
1874 for (j = 0; j < Context->vcount; j++) {
1875 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1881 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1885 /* --------------------------------------------------------------------
1886 * These functions are invoked directly from the internal-pager
1889 case OP_BOUNCE_MESSAGE:
1894 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1897 case OP_CREATE_ALIAS:
1899 mutt_create_alias (Context
1900 && Context->vcount ? CURHDR->env : NULL, NULL);
1901 MAYBE_REDRAW (menu->redraw);
1902 menu->redraw |= REDRAW_CURRENT;
1907 mutt_query_menu (NULL, 0);
1908 MAYBE_REDRAW (menu->redraw);
1911 case OP_PURGE_MESSAGE:
1918 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1921 mutt_tag_set_flag (M_DELETE, 1);
1922 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1923 if (option (OPTDELETEUNTAG))
1924 mutt_tag_set_flag (M_TAG, 0);
1925 menu->redraw = REDRAW_INDEX;
1928 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1929 mutt_set_flag (Context, CURHDR, M_PURGED,
1930 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1931 if (option (OPTDELETEUNTAG))
1932 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1933 if (option (OPTRESOLVE)) {
1934 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1935 menu->current = menu->oldcurrent;
1936 menu->redraw = REDRAW_CURRENT;
1938 else if (menu->menu == MENU_PAGER) {
1939 op = OP_DISPLAY_MESSAGE;
1943 menu->redraw |= REDRAW_MOTION_RESYNCH;
1946 menu->redraw = REDRAW_CURRENT;
1948 menu->redraw |= REDRAW_STATUS;
1951 case OP_DELETE_THREAD:
1952 case OP_DELETE_SUBTHREAD:
1958 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1960 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1961 op == OP_DELETE_THREAD ? 0 : 1);
1964 if (option (OPTDELETEUNTAG))
1965 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1966 op == OP_DELETE_THREAD ? 0 : 1);
1967 if (option (OPTRESOLVE))
1968 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1969 menu->current = menu->oldcurrent;
1970 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1976 if (Context && Context->magic == M_NNTP) {
1977 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1978 ((NNTP_DATA *) Context->data)->group))
1979 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1984 case OP_DISPLAY_ADDRESS:
1988 mutt_display_address (CURHDR->env);
1991 case OP_ENTER_COMMAND:
1993 CurrentMenu = MENU_MAIN;
1994 mutt_enter_command ();
1995 mutt_check_rescore (Context);
1996 if (option (OPTFORCEREDRAWINDEX))
1997 menu->redraw = REDRAW_FULL;
1998 unset_option (OPTFORCEREDRAWINDEX);
1999 unset_option (OPTFORCEREDRAWPAGER);
2002 case OP_EDIT_MESSAGE:
2009 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
2011 if (option (OPTPGPAUTODEC)
2012 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2013 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2014 mutt_edit_message (Context, tag ? NULL : CURHDR);
2015 menu->redraw = REDRAW_FULL;
2019 case OP_FORWARD_MESSAGE:
2025 if (option (OPTPGPAUTODEC) &&
2026 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2027 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2028 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2029 menu->redraw = REDRAW_FULL;
2033 case OP_FORGET_PASSPHRASE:
2034 crypt_forget_passphrase ();
2037 case OP_GROUP_REPLY:
2043 if (option (OPTPGPAUTODEC) &&
2044 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2045 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2047 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2048 tag ? NULL : CURHDR);
2049 menu->redraw = REDRAW_FULL;
2058 if (option (OPTPGPAUTODEC) &&
2059 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2060 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2062 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2063 tag ? NULL : CURHDR);
2064 menu->redraw = REDRAW_FULL;
2070 ci_send_message (0, NULL, NULL, Context, NULL);
2071 menu->redraw = REDRAW_FULL;
2075 if (!(WithCrypto & APPLICATION_PGP))
2078 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2079 menu->redraw = REDRAW_FULL;
2083 case OP_EXTRACT_KEYS:
2088 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2089 menu->redraw = REDRAW_FULL;
2093 case OP_CHECK_TRADITIONAL:
2094 if (!(WithCrypto & APPLICATION_PGP))
2098 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2099 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2101 if (menu->menu == MENU_PAGER) {
2102 op = OP_DISPLAY_MESSAGE;
2111 mutt_pipe_message (tag ? NULL : CURHDR);
2113 /* in an IMAP folder index with imap_peek=no, piping could change
2114 * * new or old messages status to read. Redraw what's needed.
2116 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2117 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2120 MAYBE_REDRAW (menu->redraw);
2127 mutt_print_message (tag ? NULL : CURHDR);
2129 /* in an IMAP folder index with imap_peek=no, piping could change
2130 * * new or old messages status to read. Redraw what's needed.
2132 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2133 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2138 case OP_MAIN_READ_THREAD:
2139 case OP_MAIN_READ_SUBTHREAD:
2145 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2147 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2148 op == OP_MAIN_READ_THREAD ? 0 : 1);
2151 if (option (OPTRESOLVE)) {
2152 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2153 mutt_next_thread (CURHDR) :
2154 mutt_next_subthread (CURHDR))) == -1)
2155 menu->current = menu->oldcurrent;
2157 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2161 case OP_RECALL_MESSAGE:
2164 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2165 menu->redraw = REDRAW_FULL;
2175 for (j = 0; j < Context->vcount; j++) {
2176 if (Context->hdrs[Context->v2r[j]]->tagged)
2177 mutt_resend_message (NULL, Context,
2178 Context->hdrs[Context->v2r[j]]);
2182 mutt_resend_message (NULL, Context, CURHDR);
2184 menu->redraw = REDRAW_FULL;
2190 case OP_FORWARD_TO_GROUP:
2193 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2194 Context && Context->msgcount == 0) {
2195 mutt_error (_("There are no messages."));
2198 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2199 str_casecmp (CURHDR->env->followup_to, "poster") ||
2200 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2201 _("Reply by mail as poster prefers?")) !=
2203 if (Context && Context->magic == M_NNTP
2204 && !((NNTP_DATA *) Context->data)->allowed
2205 && query_quadoption (OPT_TOMODERATED,
2207 ("Posting to this group not allowed, may be moderated. Continue?"))
2211 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2214 if (op == OP_FOLLOWUP)
2215 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2216 tag ? NULL : CURHDR);
2218 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2219 tag ? NULL : CURHDR);
2221 menu->redraw = REDRAW_FULL;
2232 if (option (OPTPGPAUTODEC) &&
2233 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2234 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2236 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2237 menu->redraw = REDRAW_FULL;
2240 case OP_SHELL_ESCAPE:
2242 mutt_shell_escape ();
2243 MAYBE_REDRAW (menu->redraw);
2247 case OP_TAG_SUBTHREAD:
2251 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2252 op == OP_TAG_THREAD ? 0 : 1);
2255 if (option (OPTRESOLVE)) {
2256 menu->current = mutt_next_thread (CURHDR);
2258 if (menu->current == -1)
2259 menu->current = menu->oldcurrent;
2261 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2271 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2274 mutt_tag_set_flag (M_DELETE, 0);
2275 mutt_tag_set_flag (M_PURGED, 0);
2276 menu->redraw = REDRAW_INDEX;
2279 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2280 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2281 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2283 menu->redraw = REDRAW_MOTION_RESYNCH;
2286 menu->redraw = REDRAW_CURRENT;
2288 menu->redraw |= REDRAW_STATUS;
2291 case OP_UNDELETE_THREAD:
2292 case OP_UNDELETE_SUBTHREAD:
2298 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2300 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2301 op == OP_UNDELETE_THREAD ? 0 : 1)
2302 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2303 op == OP_UNDELETE_THREAD ? 0 : 1);
2306 if (option (OPTRESOLVE)) {
2307 if (op == OP_UNDELETE_THREAD)
2308 menu->current = mutt_next_thread (CURHDR);
2310 menu->current = mutt_next_subthread (CURHDR);
2312 if (menu->current == -1)
2313 menu->current = menu->oldcurrent;
2315 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2324 if (option (OPTFORCEBUFFYCHECK))
2327 menu->redraw = REDRAW_FULL;
2330 case OP_VIEW_ATTACHMENTS:
2333 mutt_view_attachments (CURHDR);
2334 if (CURHDR->attach_del)
2335 Context->changed = 1;
2336 menu->redraw = REDRAW_FULL;
2346 case OP_REBUILD_CACHE:
2347 mx_rebuild_cache ();
2350 case OP_SIDEBAR_SCROLL_UP:
2351 case OP_SIDEBAR_SCROLL_DOWN:
2352 case OP_SIDEBAR_NEXT:
2353 case OP_SIDEBAR_PREV:
2354 case OP_SIDEBAR_NEXT_NEW:
2355 case OP_SIDEBAR_PREV_NEW:
2356 sidebar_scroll (op, menu->menu);
2359 if (menu->menu == MENU_MAIN)
2360 km_error_key (MENU_MAIN);
2363 if (menu->menu == MENU_PAGER) {
2364 menu->menu = MENU_MAIN;
2365 menu->redraw = REDRAW_FULL;
2367 set_option (OPTWEED); /* turn header weeding back on. */
2377 /* Close all open IMAP connections */
2381 /* Close all open NNTP connections */
2389 mutt_menuDestroy (&menu);
2393 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2400 for (color = ColorIndexList; color; color = color->next)
2401 if (mutt_pattern_exec
2402 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2403 curhdr->pair = color->pair;
2406 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];