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, 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 (j = h; !j->message; j = j->child);
318 mutt_uncollapse_thread (Context, j->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 close = 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 = 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 (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
941 mutt_message ("%s", buf);
949 menu->oldcurrent = (Context->vcount && menu->current >= 0
951 Context->vcount) ? CURHDR->index : -1;
952 if (op == OP_TOGGLE_READ) {
953 char buf[LONG_STRING];
955 if (!Context->pattern
956 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
957 snprintf (buf, sizeof (buf), "!~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 int 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 #ifdef USE_COMPRESSED
1242 if (Context->compressinfo && Context->realpath)
1243 m_strreplace(&LastFolder, Context->realpath);
1247 m_strreplace(&LastFolder, Context->path);
1248 oldcount = Context ? Context->msgcount : 0;
1250 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1251 if (check == M_NEW_MAIL || check == M_REOPENED)
1252 update_index (menu, Context, check, oldcount, index_hint);
1254 set_option (OPTSEARCHINVALID);
1255 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1263 /* Set CurrentMenu to MENU_MAIN before executing any folder
1264 * hooks so that all the index menu functions are available to
1268 CurrentMenu = MENU_MAIN;
1269 mutt_folder_hook (buf);
1271 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1272 menu->current = ci_first_message ();
1276 sidebar_set_current (buf);
1279 /* buffy_check() must be done with mail-reader mode! */
1280 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1282 && (Context->magic ==
1283 M_NNTP)) ? IndexNewsHelp :
1286 mutt_clear_error ();
1287 buffy_check (1); /* force the buffy check after we have changed
1289 menu->redraw = REDRAW_FULL;
1290 set_option (OPTSEARCHINVALID);
1293 case OP_DISPLAY_MESSAGE:
1294 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1299 * toggle the weeding of headers so that a user can press the key
1300 * again while reading the message.
1302 if (op == OP_DISPLAY_HEADERS)
1303 toggle_option (OPTWEED);
1305 unset_option (OPTNEEDRESORT);
1307 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1308 mutt_uncollapse_thread (Context, CURHDR);
1309 mutt_set_virtual (Context);
1310 if (option (OPTUNCOLLAPSEJUMP))
1311 menu->current = mutt_thread_next_unread (Context, CURHDR);
1314 if (option (OPTPGPAUTODEC) &&
1315 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1316 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1318 if ((op = mutt_display_message (CURHDR)) == -1) {
1319 unset_option (OPTNEEDRESORT);
1323 menu->menu = MENU_PAGER;
1324 menu->oldcurrent = menu->current;
1330 if (menu->menu == MENU_MAIN && attach_msg) {
1335 if ((menu->menu == MENU_MAIN)
1336 && (query_quadoption (OPT_QUIT,
1337 _("Exit Mutt-ng without saving?")) == M_YES))
1340 mx_fastclose_mailbox (Context);
1352 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1353 /* if we were in the pager, redisplay the message */
1354 if (menu->menu == MENU_PAGER) {
1355 op = OP_DISPLAY_MESSAGE;
1359 menu->redraw = REDRAW_CURRENT;
1362 case OP_MAIN_BREAK_THREAD:
1368 if ((Sort & SORT_MASK) != SORT_THREADS)
1369 mutt_error (_("Threading is not enabled."));
1373 HEADER *oldcur = CURHDR;
1375 mutt_break_thread (CURHDR);
1376 mutt_sort_headers (Context, 1);
1377 menu->current = oldcur->virtual;
1380 Context->changed = 1;
1381 mutt_message _("Thread broken");
1383 if (menu->menu == MENU_PAGER) {
1384 op = OP_DISPLAY_MESSAGE;
1388 menu->redraw |= REDRAW_INDEX;
1392 case OP_MAIN_LINK_THREADS:
1398 if ((Sort & SORT_MASK) != SORT_THREADS)
1399 mutt_error (_("Threading is not enabled."));
1401 else if (!CURHDR->env->message_id)
1402 mutt_error (_("No Message-ID: header available to link thread"));
1404 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1405 mutt_error (_("First, please tag a message to be linked here"));
1408 HEADER *oldcur = CURHDR;
1410 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1412 mutt_sort_headers (Context, 1);
1413 menu->current = oldcur->virtual;
1415 Context->changed = 1;
1416 mutt_message _("Threads linked");
1419 mutt_error (_("No thread linked"));
1422 if (menu->menu == MENU_PAGER) {
1423 op = OP_DISPLAY_MESSAGE;
1427 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1430 case OP_MAIN_NEXT_UNDELETED:
1434 if (menu->current >= Context->vcount - 1) {
1435 if (menu->menu == MENU_MAIN)
1436 mutt_error (_("You are on the last message."));
1440 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1441 menu->current = menu->oldcurrent;
1442 if (menu->menu == MENU_MAIN)
1443 mutt_error (_("No undeleted messages."));
1445 else if (menu->menu == MENU_PAGER) {
1446 op = OP_DISPLAY_MESSAGE;
1450 menu->redraw = REDRAW_MOTION;
1457 if (menu->current >= Context->vcount - 1) {
1458 if (menu->menu == MENU_MAIN)
1459 mutt_error (_("You are on the last message."));
1464 if (menu->menu == MENU_PAGER) {
1465 op = OP_DISPLAY_MESSAGE;
1469 menu->redraw = REDRAW_MOTION;
1472 case OP_MAIN_PREV_UNDELETED:
1476 if (menu->current < 1) {
1477 mutt_error (_("You are on the first message."));
1481 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1482 menu->current = menu->oldcurrent;
1483 if (menu->menu == MENU_MAIN)
1484 mutt_error (_("No undeleted messages."));
1486 else if (menu->menu == MENU_PAGER) {
1487 op = OP_DISPLAY_MESSAGE;
1491 menu->redraw = REDRAW_MOTION;
1498 if (menu->current < 1) {
1499 if (menu->menu == MENU_MAIN)
1500 mutt_error (_("You are on the first message."));
1505 if (menu->menu == MENU_PAGER) {
1506 op = OP_DISPLAY_MESSAGE;
1510 menu->redraw = REDRAW_MOTION;
1513 case OP_DECRYPT_COPY:
1514 case OP_DECRYPT_SAVE:
1518 case OP_COPY_MESSAGE:
1520 case OP_DECODE_COPY:
1521 case OP_DECODE_SAVE:
1524 if (mutt_save_message (tag ? NULL : CURHDR,
1525 (op == OP_DECRYPT_SAVE) ||
1526 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1527 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1528 (op == OP_DECRYPT_SAVE)
1529 || (op == OP_DECRYPT_COPY)
1530 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1537 menu->redraw |= REDRAW_INDEX;
1538 else if (option (OPTRESOLVE)) {
1539 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1540 menu->current = menu->oldcurrent;
1541 menu->redraw |= REDRAW_CURRENT;
1544 menu->redraw |= REDRAW_MOTION_RESYNCH;
1547 menu->redraw |= REDRAW_CURRENT;
1551 case OP_MAIN_NEXT_NEW:
1552 case OP_MAIN_NEXT_UNREAD:
1553 case OP_MAIN_PREV_NEW:
1554 case OP_MAIN_PREV_UNREAD:
1555 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1556 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1559 int first_unread = -1;
1567 for (j = 0; j != Context->vcount; j++) {
1568 #define CURHDRi Context->hdrs[Context->v2r[i]]
1569 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1570 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1572 if (i > Context->vcount - 1) {
1573 mutt_message _("Search wrapped to top.");
1581 mutt_message _("Search wrapped to bottom.");
1583 i = Context->vcount - 1;
1587 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1588 if (UNREAD (CURHDRi) && first_unread == -1)
1590 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1593 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1594 if (first_unread == -1)
1596 if ((!CURHDRi->old) && first_new == -1)
1600 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1603 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1604 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1605 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1610 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1611 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1612 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1614 menu->current = first_new;
1615 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1616 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1617 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1618 && first_unread != -1)
1619 menu->current = first_unread;
1621 if (menu->current == -1) {
1622 menu->current = menu->oldcurrent;
1623 mutt_error ("%s%s.",
1624 (op == OP_MAIN_NEXT_NEW
1626 OP_MAIN_PREV_NEW) ? _("No new messages") :
1627 _("No unread messages"),
1628 Context->pattern ? _(" in this limited view") : "");
1630 else if (menu->menu == MENU_PAGER) {
1631 op = OP_DISPLAY_MESSAGE;
1635 menu->redraw = REDRAW_MOTION;
1638 case OP_FLAG_MESSAGE:
1644 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1647 for (j = 0; j < Context->vcount; j++) {
1648 if (Context->hdrs[Context->v2r[j]]->tagged)
1649 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1650 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1653 menu->redraw |= REDRAW_INDEX;
1656 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1657 if (option (OPTRESOLVE)) {
1658 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1659 menu->current = menu->oldcurrent;
1660 menu->redraw = REDRAW_CURRENT;
1663 menu->redraw = REDRAW_MOTION_RESYNCH;
1666 menu->redraw = REDRAW_CURRENT;
1668 menu->redraw |= REDRAW_STATUS;
1677 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1680 for (j = 0; j < Context->vcount; j++) {
1681 if (Context->hdrs[Context->v2r[j]]->tagged) {
1682 if (Context->hdrs[Context->v2r[j]]->read ||
1683 Context->hdrs[Context->v2r[j]]->old)
1684 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1687 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1691 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1694 if (CURHDR->read || CURHDR->old)
1695 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1697 mutt_set_flag (Context, CURHDR, M_READ, 1);
1699 if (option (OPTRESOLVE)) {
1700 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1701 menu->current = menu->oldcurrent;
1702 menu->redraw = REDRAW_CURRENT;
1705 menu->redraw = REDRAW_MOTION_RESYNCH;
1708 menu->redraw = REDRAW_CURRENT;
1709 menu->redraw |= REDRAW_STATUS;
1713 case OP_TOGGLE_WRITE:
1716 if (mx_toggle_write (Context) == 0)
1717 menu->redraw |= REDRAW_STATUS;
1720 case OP_MAIN_NEXT_THREAD:
1721 case OP_MAIN_NEXT_SUBTHREAD:
1722 case OP_MAIN_PREV_THREAD:
1723 case OP_MAIN_PREV_SUBTHREAD:
1728 case OP_MAIN_NEXT_THREAD:
1729 menu->current = mutt_next_thread (CURHDR);
1732 case OP_MAIN_NEXT_SUBTHREAD:
1733 menu->current = mutt_next_subthread (CURHDR);
1736 case OP_MAIN_PREV_THREAD:
1737 menu->current = mutt_previous_thread (CURHDR);
1740 case OP_MAIN_PREV_SUBTHREAD:
1741 menu->current = mutt_previous_subthread (CURHDR);
1745 if (menu->current < 0) {
1746 menu->current = menu->oldcurrent;
1747 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1748 mutt_error (_("No more threads."));
1751 mutt_error (_("You are on the first thread."));
1753 else if (menu->menu == MENU_PAGER) {
1754 op = OP_DISPLAY_MESSAGE;
1758 menu->redraw = REDRAW_MOTION;
1761 case OP_MAIN_PARENT_MESSAGE:
1766 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1767 menu->current = menu->oldcurrent;
1769 else if (menu->menu == MENU_PAGER) {
1770 op = OP_DISPLAY_MESSAGE;
1774 menu->redraw = REDRAW_MOTION;
1777 case OP_MAIN_SET_FLAG:
1778 case OP_MAIN_CLEAR_FLAG:
1784 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1786 menu->redraw = REDRAW_STATUS;
1788 menu->redraw |= REDRAW_INDEX;
1789 else if (option (OPTRESOLVE)) {
1790 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1791 menu->current = menu->oldcurrent;
1792 menu->redraw |= REDRAW_CURRENT;
1795 menu->redraw |= REDRAW_MOTION_RESYNCH;
1798 menu->redraw |= REDRAW_CURRENT;
1802 case OP_MAIN_COLLAPSE_THREAD:
1806 if ((Sort & SORT_MASK) != SORT_THREADS) {
1807 mutt_error (_("Threading is not enabled."));
1812 if (CURHDR->collapsed) {
1813 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1814 mutt_set_virtual (Context);
1815 if (option (OPTUNCOLLAPSEJUMP))
1816 menu->current = mutt_thread_next_unread (Context, CURHDR);
1818 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1819 menu->current = mutt_collapse_thread (Context, CURHDR);
1820 mutt_set_virtual (Context);
1823 mutt_error (_("Thread contains unread messages."));
1828 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1832 case OP_MAIN_COLLAPSE_ALL:
1836 if ((Sort & SORT_MASK) != SORT_THREADS) {
1837 mutt_error (_("Threading is not enabled."));
1844 THREAD *thread, *top;
1847 if (CURHDR->collapsed)
1848 final = mutt_uncollapse_thread (Context, CURHDR);
1849 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1850 final = mutt_collapse_thread (Context, CURHDR);
1852 final = CURHDR->virtual;
1854 base = Context->hdrs[Context->v2r[final]];
1856 top = Context->tree;
1857 Context->collapsed = !Context->collapsed;
1858 while ((thread = top) != NULL) {
1859 while (!thread->message)
1860 thread = thread->child;
1861 h = thread->message;
1863 if (h->collapsed != Context->collapsed) {
1865 mutt_uncollapse_thread (Context, h);
1866 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1867 mutt_collapse_thread (Context, h);
1872 mutt_set_virtual (Context);
1873 for (j = 0; j < Context->vcount; j++) {
1874 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1880 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1884 /* --------------------------------------------------------------------
1885 * These functions are invoked directly from the internal-pager
1888 case OP_BOUNCE_MESSAGE:
1893 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1896 case OP_CREATE_ALIAS:
1898 mutt_create_alias (Context
1899 && Context->vcount ? CURHDR->env : NULL, NULL);
1900 MAYBE_REDRAW (menu->redraw);
1901 menu->redraw |= REDRAW_CURRENT;
1906 mutt_query_menu (NULL, 0);
1907 MAYBE_REDRAW (menu->redraw);
1910 case OP_PURGE_MESSAGE:
1917 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1920 mutt_tag_set_flag (M_DELETE, 1);
1921 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1922 if (option (OPTDELETEUNTAG))
1923 mutt_tag_set_flag (M_TAG, 0);
1924 menu->redraw = REDRAW_INDEX;
1927 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1928 mutt_set_flag (Context, CURHDR, M_PURGED,
1929 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1930 if (option (OPTDELETEUNTAG))
1931 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1932 if (option (OPTRESOLVE)) {
1933 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1934 menu->current = menu->oldcurrent;
1935 menu->redraw = REDRAW_CURRENT;
1937 else if (menu->menu == MENU_PAGER) {
1938 op = OP_DISPLAY_MESSAGE;
1942 menu->redraw |= REDRAW_MOTION_RESYNCH;
1945 menu->redraw = REDRAW_CURRENT;
1947 menu->redraw |= REDRAW_STATUS;
1950 case OP_DELETE_THREAD:
1951 case OP_DELETE_SUBTHREAD:
1957 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1959 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1960 op == OP_DELETE_THREAD ? 0 : 1);
1963 if (option (OPTDELETEUNTAG))
1964 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1965 op == OP_DELETE_THREAD ? 0 : 1);
1966 if (option (OPTRESOLVE))
1967 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1968 menu->current = menu->oldcurrent;
1969 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1975 if (Context && Context->magic == M_NNTP) {
1976 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1977 ((NNTP_DATA *) Context->data)->group))
1978 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1983 case OP_DISPLAY_ADDRESS:
1987 mutt_display_address (CURHDR->env);
1990 case OP_ENTER_COMMAND:
1992 CurrentMenu = MENU_MAIN;
1993 mutt_enter_command ();
1994 mutt_check_rescore (Context);
1995 if (option (OPTFORCEREDRAWINDEX))
1996 menu->redraw = REDRAW_FULL;
1997 unset_option (OPTFORCEREDRAWINDEX);
1998 unset_option (OPTFORCEREDRAWPAGER);
2001 case OP_EDIT_MESSAGE:
2008 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
2010 if (option (OPTPGPAUTODEC)
2011 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2012 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2013 mutt_edit_message (Context, tag ? NULL : CURHDR);
2014 menu->redraw = REDRAW_FULL;
2018 case OP_FORWARD_MESSAGE:
2024 if (option (OPTPGPAUTODEC) &&
2025 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2026 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2027 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2028 menu->redraw = REDRAW_FULL;
2032 case OP_FORGET_PASSPHRASE:
2033 crypt_forget_passphrase ();
2036 case OP_GROUP_REPLY:
2042 if (option (OPTPGPAUTODEC) &&
2043 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2044 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2046 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2047 tag ? NULL : CURHDR);
2048 menu->redraw = REDRAW_FULL;
2057 if (option (OPTPGPAUTODEC) &&
2058 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2059 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2061 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2062 tag ? NULL : CURHDR);
2063 menu->redraw = REDRAW_FULL;
2069 ci_send_message (0, NULL, NULL, Context, NULL);
2070 menu->redraw = REDRAW_FULL;
2074 if (!(WithCrypto & APPLICATION_PGP))
2077 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2078 menu->redraw = REDRAW_FULL;
2082 case OP_EXTRACT_KEYS:
2087 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2088 menu->redraw = REDRAW_FULL;
2092 case OP_CHECK_TRADITIONAL:
2093 if (!(WithCrypto & APPLICATION_PGP))
2097 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2098 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2100 if (menu->menu == MENU_PAGER) {
2101 op = OP_DISPLAY_MESSAGE;
2110 mutt_pipe_message (tag ? NULL : CURHDR);
2112 /* in an IMAP folder index with imap_peek=no, piping could change
2113 * * new or old messages status to read. Redraw what's needed.
2115 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2116 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2119 MAYBE_REDRAW (menu->redraw);
2126 mutt_print_message (tag ? NULL : CURHDR);
2128 /* in an IMAP folder index with imap_peek=no, piping could change
2129 * * new or old messages status to read. Redraw what's needed.
2131 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2132 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2137 case OP_MAIN_READ_THREAD:
2138 case OP_MAIN_READ_SUBTHREAD:
2144 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2146 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2147 op == OP_MAIN_READ_THREAD ? 0 : 1);
2150 if (option (OPTRESOLVE)) {
2151 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2152 mutt_next_thread (CURHDR) :
2153 mutt_next_subthread (CURHDR))) == -1)
2154 menu->current = menu->oldcurrent;
2156 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2160 case OP_RECALL_MESSAGE:
2163 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2164 menu->redraw = REDRAW_FULL;
2174 for (j = 0; j < Context->vcount; j++) {
2175 if (Context->hdrs[Context->v2r[j]]->tagged)
2176 mutt_resend_message (NULL, Context,
2177 Context->hdrs[Context->v2r[j]]);
2181 mutt_resend_message (NULL, Context, CURHDR);
2183 menu->redraw = REDRAW_FULL;
2189 case OP_FORWARD_TO_GROUP:
2192 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2193 Context && Context->msgcount == 0) {
2194 mutt_error (_("There are no messages."));
2197 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2198 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2199 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2200 _("Reply by mail as poster prefers?")) !=
2202 if (Context && Context->magic == M_NNTP
2203 && !((NNTP_DATA *) Context->data)->allowed
2204 && query_quadoption (OPT_TOMODERATED,
2206 ("Posting to this group not allowed, may be moderated. Continue?"))
2210 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2213 if (op == OP_FOLLOWUP)
2214 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2215 tag ? NULL : CURHDR);
2217 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2218 tag ? NULL : CURHDR);
2220 menu->redraw = REDRAW_FULL;
2231 if (option (OPTPGPAUTODEC) &&
2232 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2233 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2235 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2236 menu->redraw = REDRAW_FULL;
2239 case OP_SHELL_ESCAPE:
2241 mutt_shell_escape ();
2242 MAYBE_REDRAW (menu->redraw);
2246 case OP_TAG_SUBTHREAD:
2250 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2251 op == OP_TAG_THREAD ? 0 : 1);
2254 if (option (OPTRESOLVE)) {
2255 menu->current = mutt_next_thread (CURHDR);
2257 if (menu->current == -1)
2258 menu->current = menu->oldcurrent;
2260 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2270 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2273 mutt_tag_set_flag (M_DELETE, 0);
2274 mutt_tag_set_flag (M_PURGED, 0);
2275 menu->redraw = REDRAW_INDEX;
2278 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2279 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2280 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2282 menu->redraw = REDRAW_MOTION_RESYNCH;
2285 menu->redraw = REDRAW_CURRENT;
2287 menu->redraw |= REDRAW_STATUS;
2290 case OP_UNDELETE_THREAD:
2291 case OP_UNDELETE_SUBTHREAD:
2297 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2299 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2300 op == OP_UNDELETE_THREAD ? 0 : 1)
2301 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2302 op == OP_UNDELETE_THREAD ? 0 : 1);
2305 if (option (OPTRESOLVE)) {
2306 if (op == OP_UNDELETE_THREAD)
2307 menu->current = mutt_next_thread (CURHDR);
2309 menu->current = mutt_next_subthread (CURHDR);
2311 if (menu->current == -1)
2312 menu->current = menu->oldcurrent;
2314 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2323 if (option (OPTFORCEBUFFYCHECK))
2326 menu->redraw = REDRAW_FULL;
2329 case OP_VIEW_ATTACHMENTS:
2332 mutt_view_attachments (CURHDR);
2333 if (CURHDR->attach_del)
2334 Context->changed = 1;
2335 menu->redraw = REDRAW_FULL;
2345 case OP_REBUILD_CACHE:
2346 mx_rebuild_cache ();
2349 case OP_SIDEBAR_SCROLL_UP:
2350 case OP_SIDEBAR_SCROLL_DOWN:
2351 case OP_SIDEBAR_NEXT:
2352 case OP_SIDEBAR_PREV:
2353 case OP_SIDEBAR_NEXT_NEW:
2354 case OP_SIDEBAR_PREV_NEW:
2355 sidebar_scroll (op, menu->menu);
2358 if (menu->menu == MENU_MAIN)
2359 km_error_key (MENU_MAIN);
2362 if (menu->menu == MENU_PAGER) {
2363 menu->menu = MENU_MAIN;
2364 menu->redraw = REDRAW_FULL;
2366 set_option (OPTWEED); /* turn header weeding back on. */
2376 /* Close all open IMAP connections */
2380 /* Close all open NNTP connections */
2388 mutt_menuDestroy (&menu);
2392 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2399 for (color = ColorIndexList; color; color = color->next)
2400 if (mutt_pattern_exec
2401 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2402 curhdr->pair = color->pair;
2405 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];