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>
20 #include <lib-lib/mapping.h>
23 #include "mutt_curses.h"
25 #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 size_t UngetCount;
118 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
121 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
122 int edgemsgno, reverse = Sort & SORT_REVERSE;
123 HEADER *h = Context->hdrs[Context->v2r[num]];
126 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
127 flag |= M_FORMAT_TREE; /* display the thread tree */
128 if (h->display_subject)
129 flag |= M_FORMAT_FORCESUBJ;
132 if (menu->top + menu->pagelen > menu->max)
133 edgemsgno = Context->v2r[menu->max - 1];
135 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
138 edgemsgno = Context->v2r[menu->top];
140 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
144 /* if no ancestor is visible on current screen, provisionally force
146 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
148 flag |= M_FORMAT_FORCESUBJ;
151 else if (tmp->message->virtual >= 0)
154 if (flag & M_FORMAT_FORCESUBJ) {
155 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
159 /* ...but if a previous sibling is available, don't force it */
160 if (reverse ? tmp->message->msgno >
161 edgemsgno : tmp->message->msgno < edgemsgno)
163 else if (tmp->message->virtual >= 0) {
164 flag &= ~M_FORMAT_FORCESUBJ;
172 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
175 int index_color (int index_no)
177 HEADER *h = Context->hdrs[Context->v2r[index_no]];
182 mutt_set_header_color (Context, h);
186 static int ci_next_undeleted (int msgno)
190 for (i = msgno + 1; i < Context->vcount; i++)
191 if (!Context->hdrs[Context->v2r[i]]->deleted)
196 static int ci_previous_undeleted (int msgno)
200 for (i = msgno - 1; i >= 0; i--)
201 if (!Context->hdrs[Context->v2r[i]]->deleted)
206 /* Return the index of the first new message, or failing that, the first
209 static int ci_first_message (void)
213 if (Context && Context->msgcount) {
214 for (i = 0; i < Context->vcount; i++) {
215 if (!Context->hdrs[Context->v2r[i]]->read &&
216 !Context->hdrs[Context->v2r[i]]->deleted) {
217 if (!Context->hdrs[Context->v2r[i]]->old)
226 /* If Sort is reverse and not threaded, the latest message is first.
227 * If Sort is threaded, the latest message is first iff exactly one
228 * of Sort and SortAux are reverse.
230 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
231 ((Sort & SORT_MASK) == SORT_THREADS &&
232 ((Sort ^ SortAux) & SORT_REVERSE)))
235 return (Context->vcount ? Context->vcount - 1 : 0);
240 /* This should be in mx.c, but it only gets used here. */
241 static int mx_toggle_write (CONTEXT * ctx)
247 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
252 if (ctx->dontwrite) {
254 mutt_message (_("Changes to folder will be written on folder exit."));
258 mutt_message (_("Changes to folder will not be written."));
264 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
265 int oldcount, int index_hint)
267 /* store pointers to the newly added messages */
268 HEADER **save_new = NULL;
271 /* take note of the current message */
273 if (menu->current < Context->vcount)
274 menu->oldcurrent = index_hint;
276 oldcount = 0; /* invalid message number! */
279 /* We are in a limited view. Check if the new message(s) satisfy
280 * the limit criteria. If they do, set their virtual msgno so that
281 * they will be visible in the limited view */
282 if (Context->pattern) {
283 #define THIS_BODY Context->hdrs[j]->content
284 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
285 if (mutt_pattern_exec
286 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
288 Context->hdrs[j]->virtual = Context->vcount;
289 Context->v2r[Context->vcount] = j;
290 Context->hdrs[j]->limited = 1;
293 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
299 /* save the list of new messages */
300 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
301 save_new = p_new(HEADER*, Context->msgcount - oldcount);
302 for (j = oldcount; j < Context->msgcount; j++)
303 save_new[j - oldcount] = Context->hdrs[j];
306 /* if the mailbox was reopened, need to rethread from scratch */
307 mutt_sort_headers (Context, (check == M_REOPENED));
309 /* uncollapse threads with new mail */
310 if ((Sort & SORT_MASK) == SORT_THREADS) {
311 if (check == M_REOPENED) {
314 Context->collapsed = 0;
316 for (h = Context->tree; h; h = h->next) {
317 for (c = h; !c->message; c = c->child);
318 mutt_uncollapse_thread (Context, c->message);
320 mutt_set_virtual (Context);
323 for (j = 0; j < Context->msgcount - oldcount; j++) {
326 for (k = 0; k < Context->msgcount; k++) {
327 HEADER *h = Context->hdrs[k];
329 if (h == save_new[j] && (!Context->pattern || h->limited))
330 mutt_uncollapse_thread (Context, h);
334 mutt_set_virtual (Context);
340 /* restore the current message to the message it was pointing to */
341 for (j = 0; j < Context->vcount; j++) {
342 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
349 if (menu->current < 0)
350 menu->current = ci_first_message ();
353 static void resort_index (MUTTMENU * menu)
356 HEADER *current = CURHDR;
359 mutt_sort_headers (Context, 0);
360 /* Restore the current message */
362 for (i = 0; i < Context->vcount; i++) {
363 if (Context->hdrs[Context->v2r[i]] == current) {
369 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
370 menu->current = mutt_parent_message (Context, current);
372 if (menu->current < 0)
373 menu->current = ci_first_message ();
375 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
378 struct mapping_t IndexHelp[] = {
379 {N_("Quit"), OP_QUIT},
380 {N_("Del"), OP_DELETE},
381 {N_("Undel"), OP_UNDELETE},
382 {N_("Save"), OP_SAVE},
383 {N_("Mail"), OP_MAIL},
384 {N_("Reply"), OP_REPLY},
385 {N_("Group"), OP_GROUP_REPLY},
386 {N_("Help"), OP_HELP},
391 struct mapping_t IndexNewsHelp[] = {
392 {N_("Quit"), OP_QUIT},
393 {N_("Del"), OP_DELETE},
394 {N_("Undel"), OP_UNDELETE},
395 {N_("Save"), OP_SAVE},
396 {N_("Post"), OP_POST},
397 {N_("Followup"), OP_FOLLOWUP},
398 {N_("Catchup"), OP_CATCHUP},
399 {N_("Help"), OP_HELP},
404 /* This function handles the message index window as well as commands returned
405 * from the pager (MENU_PAGER).
407 int mutt_index_menu (void)
409 char buf[LONG_STRING], helpstr[SHORT_STRING];
412 int done = 0; /* controls when to exit the "event" loop */
414 int tag = 0; /* has the tag-prefix command been pressed? */
419 char *cp; /* temporary variable. */
420 int index_hint; /* used to restore cursor position */
421 int do_buffy_notify = 1;
422 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
423 int attach_msg = option (OPTATTACHMSG);
425 menu = mutt_new_menu ();
426 menu->menu = MENU_MAIN;
428 menu->pagelen = LINES - 3;
429 menu->make_entry = (void *) index_make_entry;
430 menu->color = index_color;
431 menu->current = ci_first_message ();
432 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
435 && (Context->magic ==
436 M_NNTP)) ? IndexNewsHelp :
441 buffy_check (1); /* force the buffy check after we enter the folder */
442 /* record folder we open to place sidebar indicator properly */
443 if (Context && Context->path)
444 sidebar_set_current (Context->path);
448 tag = 0; /* clear the tag-prefix */
450 menu->max = Context ? Context->vcount : 0;
451 oldcount = Context ? Context->msgcount : 0;
453 /* check if we need to resort the index because just about
454 * any 'op' below could do mutt_enter_command(), either here or
455 * from any new menu launched, and change $sort/$sort_aux
457 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
460 if (option (OPTREDRAWTREE) && Context && Context->msgcount
461 && (Sort & SORT_MASK) == SORT_THREADS) {
462 mutt_draw_tree (Context);
463 menu->redraw |= REDRAW_STATUS;
464 unset_option (OPTREDRAWTREE);
467 if (Context && !attach_msg) {
470 /* check for new mail in the mailbox. If nonzero, then something has
471 * changed about the file (either we got new mail or the file was
472 * modified underneath us.)
476 imap_allow_reopen (Context);
479 index_hint = (Context->vcount && menu->current >= 0
480 && menu->current < Context->vcount) ? CURHDR->index : 0;
482 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
483 if (!Context->path) {
484 /* fatal error occurred */
486 menu->redraw = REDRAW_FULL;
488 set_option (OPTSEARCHINVALID);
490 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
491 update_index (menu, Context, check, oldcount, index_hint);
493 /* notify the user of new mail */
494 if (check == M_REOPENED)
496 ("Mailbox was externally modified. Flags may be wrong."));
497 else if (check == M_NEW_MAIL) {
498 /* on new mail: redraw sidebar */
499 sidebar_draw (CurrentMenu);
500 mutt_message (_("New mail in this mailbox."));
502 if (option (OPTBEEPNEW))
505 else if (check == M_FLAGS)
506 mutt_message (_("Mailbox was externally modified."));
508 /* avoid the message being overwritten by buffy */
511 menu->redraw = REDRAW_FULL;
512 menu->max = Context->vcount;
514 set_option (OPTSEARCHINVALID);
520 imap_disallow_reopen (Context);
524 /* check for new mail in the incoming folders */
526 if ((newcount = buffy_check (0)) != oldcount) {
527 menu->redraw |= REDRAW_STATUS;
528 menu->redraw |= REDRAW_SIDEBAR;
530 if (do_buffy_notify) {
531 if (buffy_notify () && option (OPTBEEPNEW))
540 if (menu->redraw & REDRAW_SIDEBAR)
541 sidebar_draw (menu->menu);
542 if (menu->redraw & REDRAW_FULL) {
543 menu_redraw_full (menu);
544 sidebar_draw (menu->menu);
548 if (menu->menu == MENU_MAIN) {
549 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
550 menu_check_recenter (menu);
552 if (menu->redraw & REDRAW_INDEX) {
553 menu_redraw_index (menu);
554 menu->redraw |= REDRAW_STATUS;
556 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
557 menu_redraw_motion (menu);
558 else if (menu->redraw & REDRAW_CURRENT)
559 menu_redraw_current (menu);
562 if (menu->redraw & REDRAW_STATUS) {
563 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
564 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
565 sidebar_draw_frames();
566 SETCOLOR (MT_COLOR_STATUS);
567 BKGDSET (MT_COLOR_STATUS);
568 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
569 mutt_paddstr (COLS-SW, buf);
570 SETCOLOR (MT_COLOR_NORMAL);
571 BKGDSET (MT_COLOR_NORMAL);
572 sidebar_set_buffystats (Context);
573 menu->redraw &= ~REDRAW_STATUS;
574 if (option (OPTXTERMSETTITLES)) {
575 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
576 mutt_xterm_set_title (buf);
577 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
578 mutt_xterm_set_icon (buf);
583 if (menu->current < menu->max)
584 menu->oldcurrent = menu->current;
586 menu->oldcurrent = -1;
588 if (option (OPTARROWCURSOR))
589 move (menu->current - menu->top + menu->offset, 2);
590 else if (option (OPTBRAILLEFRIENDLY))
591 move (menu->current - menu->top + menu->offset, 0);
593 move (menu->current - menu->top + menu->offset, COLS - 1);
596 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
599 mutt_resize_screen ();
600 menu->redraw = REDRAW_FULL;
601 menu->menu = MENU_MAIN;
603 menu->top = 0; /* so we scroll the right amount */
605 * force a real complete redraw. clrtobot() doesn't seem to be able
606 * to handle every case without this.
608 clearok (stdscr, TRUE);
613 op = km_dokey (MENU_MAIN);
615 debug_print (4, ("Got op %d\n", op));
618 continue; /* either user abort or timeout */
622 /* special handling for the tag-prefix function */
623 if (op == OP_TAG_PREFIX) {
625 mutt_error (_("No mailbox is open."));
630 if (!Context->tagged) {
631 mutt_error (_("No tagged messages."));
637 /* give visual indication that the next command is a tag- command */
638 mvaddstr (LINES - 1, 0, "tag-");
641 /* get the real command */
642 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
643 /* abort tag sequence */
644 CLEARLINE (LINES - 1);
648 else if (option (OPTAUTOTAG) && Context && Context->tagged)
651 if (op == OP_TAG_PREFIX_COND) {
653 mutt_error (_("No mailbox is open."));
658 if (!Context->tagged) {
661 while (UngetCount > 0) {
663 if (tmp.op == OP_END_COND)
666 mutt_message (_("Nothing to do."));
672 /* give visual indication that the next command is a tag- command */
673 mvaddstr (LINES - 1, 0, "tag-");
676 /* get the real command */
677 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
678 /* abort tag sequence */
679 CLEARLINE (LINES - 1);
687 if (menu->current < menu->max)
688 menu->oldcurrent = menu->current;
690 menu->oldcurrent = -1;
692 mutt_curs_set (1); /* fallback from the pager */
696 unset_option (OPTNEWS); /* for any case */
701 /* ----------------------------------------------------------------------
706 menu_bottom_page (menu);
709 menu_first_entry (menu);
712 menu_middle_page (menu);
718 menu_half_down (menu);
721 menu_next_line (menu);
724 menu_prev_line (menu);
727 menu_next_page (menu);
730 menu_prev_page (menu);
733 menu_last_entry (menu);
736 menu_top_page (menu);
739 menu_current_top (menu);
741 case OP_CURRENT_MIDDLE:
742 menu_current_middle (menu);
744 case OP_CURRENT_BOTTOM:
745 menu_current_bottom (menu);
752 if (Context->magic == M_NNTP) {
755 if (op == OP_GET_MESSAGE) {
757 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
762 LIST *ref = CURHDR->env->references;
765 mutt_error (_("Article has no parent reference!"));
769 m_strcpy(buf, sizeof(buf), ref->data);
771 if (!Context->id_hash)
772 Context->id_hash = mutt_make_id_hash (Context);
773 if ((h = hash_find (Context->id_hash, buf))) {
774 if (h->virtual != -1) {
775 menu->current = h->virtual;
776 menu->redraw = REDRAW_MOTION_RESYNCH;
778 else if (h->collapsed) {
779 mutt_uncollapse_thread (Context, h);
780 mutt_set_virtual (Context);
781 menu->current = h->virtual;
782 menu->redraw = REDRAW_MOTION_RESYNCH;
785 mutt_error (_("Message not visible in limited view."));
788 if (nntp_check_msgid (Context, buf) == 0) {
789 h = Context->hdrs[Context->msgcount - 1];
790 mutt_sort_headers (Context, 0);
791 menu->current = h->virtual;
792 menu->redraw = REDRAW_FULL;
795 mutt_error (_("Article %s not found on server"), buf);
800 case OP_GET_CHILDREN:
801 case OP_RECONSTRUCT_THREAD:
803 if (Context->magic == M_NNTP) {
805 int old = CURHDR->index, i;
807 if (!CURHDR->env->message_id) {
808 mutt_error (_("No Message-ID. Unable to perform operation"));
813 if (!Context->id_hash)
814 Context->id_hash = mutt_make_id_hash (Context);
815 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
817 if (op == OP_RECONSTRUCT_THREAD) {
818 LIST *ref = CURHDR->env->references;
821 nntp_check_msgid (Context, ref->data);
822 /* the last msgid in References is the root message */
824 m_strcpy(buf, sizeof(buf), ref->data);
828 mutt_message (_("Check for children of message..."));
830 if (nntp_check_children (Context, buf) == 0) {
831 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
832 h = hash_find (Context->id_hash, buf);
833 /* if the root message was retrieved, move to it */
835 menu->current = h->virtual;
836 else /* try to restore old position */
837 for (i = 0; i < Context->msgcount; i++)
838 if (Context->hdrs[i]->index == old) {
839 menu->current = Context->hdrs[i]->virtual;
840 /* As an added courtesy, recenter the menu
841 * with the current entry at the middle of the screen */
842 menu_check_recenter (menu);
843 menu_current_middle (menu);
846 menu->redraw = REDRAW_FULL;
856 if (isdigit (LastKey))
857 mutt_ungetch (LastKey, 0);
859 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
863 if (!isdigit ((unsigned char) buf[0])) {
864 mutt_error (_("Argument must be a message number."));
870 if (i > 0 && i <= Context->msgcount) {
871 for (j = i - 1; j < Context->msgcount; j++) {
872 if (Context->hdrs[j]->virtual != -1)
875 if (j >= Context->msgcount) {
876 for (j = i - 2; j >= 0; j--) {
877 if (Context->hdrs[j]->virtual != -1)
883 menu->current = Context->hdrs[j]->virtual;
884 if (menu->menu == MENU_PAGER) {
885 op = OP_DISPLAY_MESSAGE;
889 menu->redraw = REDRAW_MOTION;
892 mutt_error (_("That message is not visible."));
895 mutt_error (_("Invalid message number."));
899 /* --------------------------------------------------------------------
900 * `index' specific commands
903 case OP_MAIN_DELETE_PATTERN:
909 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
912 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
913 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
917 case OP_MAIN_FETCH_MAIL:
921 menu->redraw = REDRAW_FULL;
927 mutt_help (MENU_MAIN);
928 menu->redraw = REDRAW_FULL;
931 case OP_MAIN_SHOW_LIMIT:
933 if (!Context->pattern)
934 mutt_message (_("No limit pattern is in effect."));
939 /* i18n: ask for a limit to apply */
940 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
941 mutt_message ("%s", buffer);
949 menu->oldcurrent = (Context->vcount && menu->current >= 0
951 Context->vcount) ? CURHDR->index : -1;
952 if (op == OP_TOGGLE_READ) {
953 char buffer[LONG_STRING];
955 if (!Context->pattern
956 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
957 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
958 Context->pattern ? Context->pattern : ".*");
959 set_option (OPTHIDEREAD);
962 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
963 if (!*buf || strncmp (buf, ".*", 2) == 0)
964 snprintf (buf, sizeof (buf), "~A");
965 unset_option (OPTHIDEREAD);
967 p_delete(&Context->pattern);
968 Context->pattern = m_strdup(buf);
970 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
971 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
973 if (menu->oldcurrent >= 0) {
974 /* try to find what used to be the current message */
976 for (i = 0; i < Context->vcount; i++)
977 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
981 if (menu->current < 0)
986 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
987 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
988 mutt_draw_tree (Context);
989 menu->redraw = REDRAW_FULL;
991 if (Context->pattern)
992 mutt_message _("To view all messages, limit to \"all\".");
1003 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1006 oldcount = Context ? Context->msgcount : 0;
1009 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1012 if (check == M_NEW_MAIL || check == M_REOPENED)
1013 update_index (menu, Context, check, oldcount, index_hint);
1015 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1016 set_option (OPTSEARCHINVALID);
1023 clearok (stdscr, TRUE);
1024 menu->redraw = REDRAW_FULL;
1028 case OP_SEARCH_REVERSE:
1029 case OP_SEARCH_NEXT:
1030 case OP_SEARCH_OPPOSITE:
1034 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1035 menu->current = menu->oldcurrent;
1037 menu->redraw = REDRAW_MOTION;
1041 case OP_SORT_REVERSE:
1043 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1044 if (Context && Context->msgcount) {
1045 resort_index (menu);
1046 set_option (OPTSEARCHINVALID);
1055 if (tag && !option (OPTAUTOTAG)) {
1056 for (j = 0; j < Context->vcount; j++)
1057 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1058 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1061 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1062 Context->last_tag = CURHDR->tagged ? CURHDR :
1063 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1064 ? NULL : Context->last_tag);
1065 menu->redraw = REDRAW_STATUS;
1066 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1068 menu->redraw |= REDRAW_MOTION_RESYNCH;
1071 menu->redraw |= REDRAW_CURRENT;
1075 case OP_MAIN_TAG_PATTERN:
1079 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1080 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1083 case OP_MAIN_UNDELETE_PATTERN:
1089 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1091 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1093 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1096 case OP_MAIN_UNTAG_PATTERN:
1100 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1101 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1104 /* --------------------------------------------------------------------
1105 * The following operations can be performed inside of the pager.
1109 case OP_MAIN_IMAP_FETCH:
1110 if (Context->magic == M_IMAP)
1111 imap_check_mailbox (Context, &index_hint, 1);
1115 case OP_MAIN_SYNC_FOLDER:
1117 if (Context && !Context->msgcount)
1124 int oldvcount = Context->vcount;
1125 oldcount = Context->msgcount;
1129 /* calculate the number of messages _above_ the cursor,
1130 * so we can keep the cursor on the current message
1132 for (j = 0; j <= menu->current; j++) {
1133 if (Context->hdrs[Context->v2r[j]]->deleted)
1137 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1138 if (Context->vcount != oldvcount)
1139 menu->current -= dcount;
1140 set_option (OPTSEARCHINVALID);
1142 else if (check == M_NEW_MAIL || check == M_REOPENED)
1143 update_index (menu, Context, check, oldcount, index_hint);
1146 * do a sanity check even if mx_sync_mailbox failed.
1149 if (menu->current < 0 || menu->current >= Context->vcount)
1150 menu->current = ci_first_message ();
1153 /* check for a fatal error, or all messages deleted */
1157 /* if we were in the pager, redisplay the message */
1158 if (menu->menu == MENU_PAGER) {
1159 op = OP_DISPLAY_MESSAGE;
1163 menu->redraw = REDRAW_FULL;
1166 case OP_SIDEBAR_OPEN:
1167 case OP_MAIN_CHANGE_FOLDER:
1168 case OP_MAIN_CHANGE_FOLDER_READONLY:
1170 case OP_MAIN_CHANGE_GROUP:
1171 case OP_MAIN_CHANGE_GROUP_READONLY:
1173 if (attach_msg || option (OPTREADONLY) ||
1175 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1177 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1183 cp = _("Open mailbox in read-only mode");
1185 cp = _("Open mailbox");
1189 unset_option (OPTNEWS);
1190 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1191 set_option (OPTNEWS);
1192 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1195 cp = _("Open newsgroup in read-only mode");
1197 cp = _("Open newsgroup");
1198 nntp_buffy (buf, sizeof (buf));
1203 if (Context && Context->path)
1204 m_strcpy(buf, sizeof(buf), Context->path);
1205 if (op != OP_SIDEBAR_OPEN)
1206 buffy_next (buf, sizeof (buf));
1209 if (op == OP_SIDEBAR_OPEN) {
1210 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1212 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1213 if (menu->menu == MENU_PAGER) {
1214 op = OP_DISPLAY_MESSAGE;
1220 CLEARLINE (LINES - 1);
1225 if (option (OPTNEWS)) {
1226 unset_option (OPTNEWS);
1227 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1231 mutt_expand_path (buf, sizeof (buf));
1232 if (mx_get_magic (buf) <= 0) {
1233 mutt_error (_("%s is not a mailbox."), buf);
1236 m_strreplace(&CurrentFolder, buf);
1241 if (Context->compressinfo && Context->realpath)
1242 m_strreplace(&LastFolder, Context->realpath);
1244 m_strreplace(&LastFolder, Context->path);
1245 oldcount = Context ? Context->msgcount : 0;
1247 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1248 if (check == M_NEW_MAIL || check == M_REOPENED)
1249 update_index (menu, Context, check, oldcount, index_hint);
1251 set_option (OPTSEARCHINVALID);
1252 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1260 /* Set CurrentMenu to MENU_MAIN before executing any folder
1261 * hooks so that all the index menu functions are available to
1265 CurrentMenu = MENU_MAIN;
1266 mutt_folder_hook (buf);
1268 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1269 menu->current = ci_first_message ();
1273 sidebar_set_current (buf);
1276 /* buffy_check() must be done with mail-reader mode! */
1277 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1279 && (Context->magic ==
1280 M_NNTP)) ? IndexNewsHelp :
1283 mutt_clear_error ();
1284 buffy_check (1); /* force the buffy check after we have changed
1286 menu->redraw = REDRAW_FULL;
1287 set_option (OPTSEARCHINVALID);
1290 case OP_DISPLAY_MESSAGE:
1291 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1296 * toggle the weeding of headers so that a user can press the key
1297 * again while reading the message.
1299 if (op == OP_DISPLAY_HEADERS)
1300 toggle_option (OPTWEED);
1302 unset_option (OPTNEEDRESORT);
1304 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1305 mutt_uncollapse_thread (Context, CURHDR);
1306 mutt_set_virtual (Context);
1307 if (option (OPTUNCOLLAPSEJUMP))
1308 menu->current = mutt_thread_next_unread (Context, CURHDR);
1311 if (option (OPTPGPAUTODEC) &&
1312 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1313 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1315 if ((op = mutt_display_message (CURHDR)) == -1) {
1316 unset_option (OPTNEEDRESORT);
1320 menu->menu = MENU_PAGER;
1321 menu->oldcurrent = menu->current;
1327 if (menu->menu == MENU_MAIN && attach_msg) {
1332 if ((menu->menu == MENU_MAIN)
1333 && (query_quadoption (OPT_QUIT,
1334 _("Exit Mutt-ng without saving?")) == M_YES))
1337 mx_fastclose_mailbox (Context);
1349 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1350 /* if we were in the pager, redisplay the message */
1351 if (menu->menu == MENU_PAGER) {
1352 op = OP_DISPLAY_MESSAGE;
1356 menu->redraw = REDRAW_CURRENT;
1359 case OP_MAIN_BREAK_THREAD:
1365 if ((Sort & SORT_MASK) != SORT_THREADS)
1366 mutt_error (_("Threading is not enabled."));
1370 HEADER *oldcur = CURHDR;
1372 mutt_break_thread (CURHDR);
1373 mutt_sort_headers (Context, 1);
1374 menu->current = oldcur->virtual;
1377 Context->changed = 1;
1378 mutt_message _("Thread broken");
1380 if (menu->menu == MENU_PAGER) {
1381 op = OP_DISPLAY_MESSAGE;
1385 menu->redraw |= REDRAW_INDEX;
1389 case OP_MAIN_LINK_THREADS:
1395 if ((Sort & SORT_MASK) != SORT_THREADS)
1396 mutt_error (_("Threading is not enabled."));
1398 else if (!CURHDR->env->message_id)
1399 mutt_error (_("No Message-ID: header available to link thread"));
1401 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1402 mutt_error (_("First, please tag a message to be linked here"));
1405 HEADER *oldcur = CURHDR;
1407 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1409 mutt_sort_headers (Context, 1);
1410 menu->current = oldcur->virtual;
1412 Context->changed = 1;
1413 mutt_message _("Threads linked");
1416 mutt_error (_("No thread linked"));
1419 if (menu->menu == MENU_PAGER) {
1420 op = OP_DISPLAY_MESSAGE;
1424 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1427 case OP_MAIN_NEXT_UNDELETED:
1431 if (menu->current >= Context->vcount - 1) {
1432 if (menu->menu == MENU_MAIN)
1433 mutt_error (_("You are on the last message."));
1437 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1438 menu->current = menu->oldcurrent;
1439 if (menu->menu == MENU_MAIN)
1440 mutt_error (_("No undeleted messages."));
1442 else if (menu->menu == MENU_PAGER) {
1443 op = OP_DISPLAY_MESSAGE;
1447 menu->redraw = REDRAW_MOTION;
1454 if (menu->current >= Context->vcount - 1) {
1455 if (menu->menu == MENU_MAIN)
1456 mutt_error (_("You are on the last message."));
1461 if (menu->menu == MENU_PAGER) {
1462 op = OP_DISPLAY_MESSAGE;
1466 menu->redraw = REDRAW_MOTION;
1469 case OP_MAIN_PREV_UNDELETED:
1473 if (menu->current < 1) {
1474 mutt_error (_("You are on the first message."));
1478 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1479 menu->current = menu->oldcurrent;
1480 if (menu->menu == MENU_MAIN)
1481 mutt_error (_("No undeleted messages."));
1483 else if (menu->menu == MENU_PAGER) {
1484 op = OP_DISPLAY_MESSAGE;
1488 menu->redraw = REDRAW_MOTION;
1495 if (menu->current < 1) {
1496 if (menu->menu == MENU_MAIN)
1497 mutt_error (_("You are on the first message."));
1502 if (menu->menu == MENU_PAGER) {
1503 op = OP_DISPLAY_MESSAGE;
1507 menu->redraw = REDRAW_MOTION;
1510 case OP_DECRYPT_COPY:
1511 case OP_DECRYPT_SAVE:
1512 case OP_COPY_MESSAGE:
1514 case OP_DECODE_COPY:
1515 case OP_DECODE_SAVE:
1518 if (mutt_save_message (tag ? NULL : CURHDR,
1519 (op == OP_DECRYPT_SAVE) ||
1520 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1521 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1522 (op == OP_DECRYPT_SAVE)
1523 || (op == OP_DECRYPT_COPY)
1524 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1531 menu->redraw |= REDRAW_INDEX;
1532 else if (option (OPTRESOLVE)) {
1533 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1534 menu->current = menu->oldcurrent;
1535 menu->redraw |= REDRAW_CURRENT;
1538 menu->redraw |= REDRAW_MOTION_RESYNCH;
1541 menu->redraw |= REDRAW_CURRENT;
1545 case OP_MAIN_NEXT_NEW:
1546 case OP_MAIN_NEXT_UNREAD:
1547 case OP_MAIN_PREV_NEW:
1548 case OP_MAIN_PREV_UNREAD:
1549 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1550 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1553 int first_unread = -1;
1561 for (j = 0; j != Context->vcount; j++) {
1562 #define CURHDRi Context->hdrs[Context->v2r[i]]
1563 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1564 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1566 if (i > Context->vcount - 1) {
1567 mutt_message _("Search wrapped to top.");
1575 mutt_message _("Search wrapped to bottom.");
1577 i = Context->vcount - 1;
1581 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1582 if (UNREAD (CURHDRi) && first_unread == -1)
1584 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1587 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1588 if (first_unread == -1)
1590 if ((!CURHDRi->old) && first_new == -1)
1594 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1597 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1598 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1599 || op == OP_MAIN_PREV_NEW_THEN_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)
1608 menu->current = first_new;
1609 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1610 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1611 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1612 && first_unread != -1)
1613 menu->current = first_unread;
1615 if (menu->current == -1) {
1616 menu->current = menu->oldcurrent;
1617 mutt_error ("%s%s.",
1618 (op == OP_MAIN_NEXT_NEW
1620 OP_MAIN_PREV_NEW) ? _("No new messages") :
1621 _("No unread messages"),
1622 Context->pattern ? _(" in this limited view") : "");
1624 else if (menu->menu == MENU_PAGER) {
1625 op = OP_DISPLAY_MESSAGE;
1629 menu->redraw = REDRAW_MOTION;
1632 case OP_FLAG_MESSAGE:
1638 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1641 for (j = 0; j < Context->vcount; j++) {
1642 if (Context->hdrs[Context->v2r[j]]->tagged)
1643 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1644 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1647 menu->redraw |= REDRAW_INDEX;
1650 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1651 if (option (OPTRESOLVE)) {
1652 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1653 menu->current = menu->oldcurrent;
1654 menu->redraw = REDRAW_CURRENT;
1657 menu->redraw = REDRAW_MOTION_RESYNCH;
1660 menu->redraw = REDRAW_CURRENT;
1662 menu->redraw |= REDRAW_STATUS;
1671 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1674 for (j = 0; j < Context->vcount; j++) {
1675 if (Context->hdrs[Context->v2r[j]]->tagged) {
1676 if (Context->hdrs[Context->v2r[j]]->read ||
1677 Context->hdrs[Context->v2r[j]]->old)
1678 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1681 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1685 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1688 if (CURHDR->read || CURHDR->old)
1689 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1691 mutt_set_flag (Context, CURHDR, M_READ, 1);
1693 if (option (OPTRESOLVE)) {
1694 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1695 menu->current = menu->oldcurrent;
1696 menu->redraw = REDRAW_CURRENT;
1699 menu->redraw = REDRAW_MOTION_RESYNCH;
1702 menu->redraw = REDRAW_CURRENT;
1703 menu->redraw |= REDRAW_STATUS;
1707 case OP_TOGGLE_WRITE:
1710 if (mx_toggle_write (Context) == 0)
1711 menu->redraw |= REDRAW_STATUS;
1714 case OP_MAIN_NEXT_THREAD:
1715 case OP_MAIN_NEXT_SUBTHREAD:
1716 case OP_MAIN_PREV_THREAD:
1717 case OP_MAIN_PREV_SUBTHREAD:
1722 case OP_MAIN_NEXT_THREAD:
1723 menu->current = mutt_next_thread (CURHDR);
1726 case OP_MAIN_NEXT_SUBTHREAD:
1727 menu->current = mutt_next_subthread (CURHDR);
1730 case OP_MAIN_PREV_THREAD:
1731 menu->current = mutt_previous_thread (CURHDR);
1734 case OP_MAIN_PREV_SUBTHREAD:
1735 menu->current = mutt_previous_subthread (CURHDR);
1739 if (menu->current < 0) {
1740 menu->current = menu->oldcurrent;
1741 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1742 mutt_error (_("No more threads."));
1745 mutt_error (_("You are on the first thread."));
1747 else if (menu->menu == MENU_PAGER) {
1748 op = OP_DISPLAY_MESSAGE;
1752 menu->redraw = REDRAW_MOTION;
1755 case OP_MAIN_PARENT_MESSAGE:
1760 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1761 menu->current = menu->oldcurrent;
1763 else if (menu->menu == MENU_PAGER) {
1764 op = OP_DISPLAY_MESSAGE;
1768 menu->redraw = REDRAW_MOTION;
1771 case OP_MAIN_SET_FLAG:
1772 case OP_MAIN_CLEAR_FLAG:
1778 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1780 menu->redraw = REDRAW_STATUS;
1782 menu->redraw |= REDRAW_INDEX;
1783 else if (option (OPTRESOLVE)) {
1784 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1785 menu->current = menu->oldcurrent;
1786 menu->redraw |= REDRAW_CURRENT;
1789 menu->redraw |= REDRAW_MOTION_RESYNCH;
1792 menu->redraw |= REDRAW_CURRENT;
1796 case OP_MAIN_COLLAPSE_THREAD:
1800 if ((Sort & SORT_MASK) != SORT_THREADS) {
1801 mutt_error (_("Threading is not enabled."));
1806 if (CURHDR->collapsed) {
1807 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1808 mutt_set_virtual (Context);
1809 if (option (OPTUNCOLLAPSEJUMP))
1810 menu->current = mutt_thread_next_unread (Context, CURHDR);
1812 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1813 menu->current = mutt_collapse_thread (Context, CURHDR);
1814 mutt_set_virtual (Context);
1817 mutt_error (_("Thread contains unread messages."));
1822 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1826 case OP_MAIN_COLLAPSE_ALL:
1830 if ((Sort & SORT_MASK) != SORT_THREADS) {
1831 mutt_error (_("Threading is not enabled."));
1838 THREAD *thread, *top;
1841 if (CURHDR->collapsed)
1842 final = mutt_uncollapse_thread (Context, CURHDR);
1843 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1844 final = mutt_collapse_thread (Context, CURHDR);
1846 final = CURHDR->virtual;
1848 base = Context->hdrs[Context->v2r[final]];
1850 top = Context->tree;
1851 Context->collapsed = !Context->collapsed;
1852 while ((thread = top) != NULL) {
1853 while (!thread->message)
1854 thread = thread->child;
1855 h = thread->message;
1857 if (h->collapsed != Context->collapsed) {
1859 mutt_uncollapse_thread (Context, h);
1860 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1861 mutt_collapse_thread (Context, h);
1866 mutt_set_virtual (Context);
1867 for (j = 0; j < Context->vcount; j++) {
1868 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1874 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1878 /* --------------------------------------------------------------------
1879 * These functions are invoked directly from the internal-pager
1882 case OP_BOUNCE_MESSAGE:
1887 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1890 case OP_CREATE_ALIAS:
1892 mutt_create_alias (Context
1893 && Context->vcount ? CURHDR->env : NULL, NULL);
1894 MAYBE_REDRAW (menu->redraw);
1895 menu->redraw |= REDRAW_CURRENT;
1900 mutt_query_menu (NULL, 0);
1901 MAYBE_REDRAW (menu->redraw);
1904 case OP_PURGE_MESSAGE:
1911 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1914 mutt_tag_set_flag (M_DELETE, 1);
1915 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1916 if (option (OPTDELETEUNTAG))
1917 mutt_tag_set_flag (M_TAG, 0);
1918 menu->redraw = REDRAW_INDEX;
1921 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1922 mutt_set_flag (Context, CURHDR, M_PURGED,
1923 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1924 if (option (OPTDELETEUNTAG))
1925 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1926 if (option (OPTRESOLVE)) {
1927 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1928 menu->current = menu->oldcurrent;
1929 menu->redraw = REDRAW_CURRENT;
1931 else if (menu->menu == MENU_PAGER) {
1932 op = OP_DISPLAY_MESSAGE;
1936 menu->redraw |= REDRAW_MOTION_RESYNCH;
1939 menu->redraw = REDRAW_CURRENT;
1941 menu->redraw |= REDRAW_STATUS;
1944 case OP_DELETE_THREAD:
1945 case OP_DELETE_SUBTHREAD:
1951 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1953 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1954 op == OP_DELETE_THREAD ? 0 : 1);
1957 if (option (OPTDELETEUNTAG))
1958 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1959 op == OP_DELETE_THREAD ? 0 : 1);
1960 if (option (OPTRESOLVE))
1961 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1962 menu->current = menu->oldcurrent;
1963 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1969 if (Context && Context->magic == M_NNTP) {
1970 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1971 ((NNTP_DATA *) Context->data)->group))
1972 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1977 case OP_DISPLAY_ADDRESS:
1981 mutt_display_address (CURHDR->env);
1984 case OP_ENTER_COMMAND:
1986 CurrentMenu = MENU_MAIN;
1987 mutt_enter_command ();
1988 mutt_check_rescore (Context);
1989 if (option (OPTFORCEREDRAWINDEX))
1990 menu->redraw = REDRAW_FULL;
1991 unset_option (OPTFORCEREDRAWINDEX);
1992 unset_option (OPTFORCEREDRAWPAGER);
1995 case OP_EDIT_MESSAGE:
2002 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
2004 if (option (OPTPGPAUTODEC)
2005 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2006 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2007 mutt_edit_message (Context, tag ? NULL : CURHDR);
2008 menu->redraw = REDRAW_FULL;
2012 case OP_FORWARD_MESSAGE:
2018 if (option (OPTPGPAUTODEC) &&
2019 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2020 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2021 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2022 menu->redraw = REDRAW_FULL;
2026 case OP_FORGET_PASSPHRASE:
2027 crypt_forget_passphrase ();
2030 case OP_GROUP_REPLY:
2036 if (option (OPTPGPAUTODEC) &&
2037 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2038 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2040 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2041 tag ? NULL : CURHDR);
2042 menu->redraw = REDRAW_FULL;
2051 if (option (OPTPGPAUTODEC) &&
2052 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2053 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2055 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2056 tag ? NULL : CURHDR);
2057 menu->redraw = REDRAW_FULL;
2063 ci_send_message (0, NULL, NULL, Context, NULL);
2064 menu->redraw = REDRAW_FULL;
2069 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2070 menu->redraw = REDRAW_FULL;
2074 case OP_EXTRACT_KEYS:
2077 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2078 menu->redraw = REDRAW_FULL;
2082 case OP_CHECK_TRADITIONAL:
2085 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2086 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2088 if (menu->menu == MENU_PAGER) {
2089 op = OP_DISPLAY_MESSAGE;
2098 mutt_pipe_message (tag ? NULL : CURHDR);
2100 /* in an IMAP folder index with imap_peek=no, piping could change
2101 * * new or old messages status to read. Redraw what's needed.
2103 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2104 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2107 MAYBE_REDRAW (menu->redraw);
2114 mutt_print_message (tag ? NULL : CURHDR);
2116 /* in an IMAP folder index with imap_peek=no, piping could change
2117 * * new or old messages status to read. Redraw what's needed.
2119 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2120 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2125 case OP_MAIN_READ_THREAD:
2126 case OP_MAIN_READ_SUBTHREAD:
2132 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2134 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2135 op == OP_MAIN_READ_THREAD ? 0 : 1);
2138 if (option (OPTRESOLVE)) {
2139 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2140 mutt_next_thread (CURHDR) :
2141 mutt_next_subthread (CURHDR))) == -1)
2142 menu->current = menu->oldcurrent;
2144 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2148 case OP_RECALL_MESSAGE:
2151 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2152 menu->redraw = REDRAW_FULL;
2162 for (j = 0; j < Context->vcount; j++) {
2163 if (Context->hdrs[Context->v2r[j]]->tagged)
2164 mutt_resend_message (NULL, Context,
2165 Context->hdrs[Context->v2r[j]]);
2169 mutt_resend_message (NULL, Context, CURHDR);
2171 menu->redraw = REDRAW_FULL;
2177 case OP_FORWARD_TO_GROUP:
2180 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2181 Context && Context->msgcount == 0) {
2182 mutt_error (_("There are no messages."));
2185 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2186 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2187 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2188 _("Reply by mail as poster prefers?")) !=
2190 if (Context && Context->magic == M_NNTP
2191 && !((NNTP_DATA *) Context->data)->allowed
2192 && query_quadoption (OPT_TOMODERATED,
2194 ("Posting to this group not allowed, may be moderated. Continue?"))
2198 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2201 if (op == OP_FOLLOWUP)
2202 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2203 tag ? NULL : CURHDR);
2205 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2206 tag ? NULL : CURHDR);
2208 menu->redraw = REDRAW_FULL;
2219 if (option (OPTPGPAUTODEC) &&
2220 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2221 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2223 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2224 menu->redraw = REDRAW_FULL;
2227 case OP_SHELL_ESCAPE:
2229 mutt_shell_escape ();
2230 MAYBE_REDRAW (menu->redraw);
2234 case OP_TAG_SUBTHREAD:
2238 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2239 op == OP_TAG_THREAD ? 0 : 1);
2242 if (option (OPTRESOLVE)) {
2243 menu->current = mutt_next_thread (CURHDR);
2245 if (menu->current == -1)
2246 menu->current = menu->oldcurrent;
2248 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2258 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2261 mutt_tag_set_flag (M_DELETE, 0);
2262 mutt_tag_set_flag (M_PURGED, 0);
2263 menu->redraw = REDRAW_INDEX;
2266 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2267 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2268 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2270 menu->redraw = REDRAW_MOTION_RESYNCH;
2273 menu->redraw = REDRAW_CURRENT;
2275 menu->redraw |= REDRAW_STATUS;
2278 case OP_UNDELETE_THREAD:
2279 case OP_UNDELETE_SUBTHREAD:
2285 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2287 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2288 op == OP_UNDELETE_THREAD ? 0 : 1)
2289 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2290 op == OP_UNDELETE_THREAD ? 0 : 1);
2293 if (option (OPTRESOLVE)) {
2294 if (op == OP_UNDELETE_THREAD)
2295 menu->current = mutt_next_thread (CURHDR);
2297 menu->current = mutt_next_subthread (CURHDR);
2299 if (menu->current == -1)
2300 menu->current = menu->oldcurrent;
2302 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2311 if (option (OPTFORCEBUFFYCHECK))
2314 menu->redraw = REDRAW_FULL;
2317 case OP_VIEW_ATTACHMENTS:
2320 mutt_view_attachments (CURHDR);
2321 if (CURHDR->attach_del)
2322 Context->changed = 1;
2323 menu->redraw = REDRAW_FULL;
2333 case OP_REBUILD_CACHE:
2334 mx_rebuild_cache ();
2337 case OP_SIDEBAR_SCROLL_UP:
2338 case OP_SIDEBAR_SCROLL_DOWN:
2339 case OP_SIDEBAR_NEXT:
2340 case OP_SIDEBAR_PREV:
2341 case OP_SIDEBAR_NEXT_NEW:
2342 case OP_SIDEBAR_PREV_NEW:
2343 sidebar_scroll (op, menu->menu);
2346 if (menu->menu == MENU_MAIN)
2347 km_error_key (MENU_MAIN);
2350 if (menu->menu == MENU_PAGER) {
2351 menu->menu = MENU_MAIN;
2352 menu->redraw = REDRAW_FULL;
2354 set_option (OPTWEED); /* turn header weeding back on. */
2364 /* Close all open IMAP connections */
2368 /* Close all open NNTP connections */
2376 mutt_menuDestroy (&menu);
2380 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2387 for (color = ColorIndexList; color; color = color->next)
2388 if (mutt_pattern_exec
2389 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2390 curhdr->pair = color->pair;
2393 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];