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 #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:
1515 case OP_COPY_MESSAGE:
1517 case OP_DECODE_COPY:
1518 case OP_DECODE_SAVE:
1521 if (mutt_save_message (tag ? NULL : CURHDR,
1522 (op == OP_DECRYPT_SAVE) ||
1523 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1524 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1525 (op == OP_DECRYPT_SAVE)
1526 || (op == OP_DECRYPT_COPY)
1527 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1534 menu->redraw |= REDRAW_INDEX;
1535 else if (option (OPTRESOLVE)) {
1536 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1537 menu->current = menu->oldcurrent;
1538 menu->redraw |= REDRAW_CURRENT;
1541 menu->redraw |= REDRAW_MOTION_RESYNCH;
1544 menu->redraw |= REDRAW_CURRENT;
1548 case OP_MAIN_NEXT_NEW:
1549 case OP_MAIN_NEXT_UNREAD:
1550 case OP_MAIN_PREV_NEW:
1551 case OP_MAIN_PREV_UNREAD:
1552 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1553 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1556 int first_unread = -1;
1564 for (j = 0; j != Context->vcount; j++) {
1565 #define CURHDRi Context->hdrs[Context->v2r[i]]
1566 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1567 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1569 if (i > Context->vcount - 1) {
1570 mutt_message _("Search wrapped to top.");
1578 mutt_message _("Search wrapped to bottom.");
1580 i = Context->vcount - 1;
1584 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1585 if (UNREAD (CURHDRi) && first_unread == -1)
1587 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1590 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1591 if (first_unread == -1)
1593 if ((!CURHDRi->old) && first_new == -1)
1597 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1600 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1601 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1602 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1607 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1608 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1609 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1611 menu->current = first_new;
1612 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1613 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1614 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1615 && first_unread != -1)
1616 menu->current = first_unread;
1618 if (menu->current == -1) {
1619 menu->current = menu->oldcurrent;
1620 mutt_error ("%s%s.",
1621 (op == OP_MAIN_NEXT_NEW
1623 OP_MAIN_PREV_NEW) ? _("No new messages") :
1624 _("No unread messages"),
1625 Context->pattern ? _(" in this limited view") : "");
1627 else if (menu->menu == MENU_PAGER) {
1628 op = OP_DISPLAY_MESSAGE;
1632 menu->redraw = REDRAW_MOTION;
1635 case OP_FLAG_MESSAGE:
1641 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1644 for (j = 0; j < Context->vcount; j++) {
1645 if (Context->hdrs[Context->v2r[j]]->tagged)
1646 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1647 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1650 menu->redraw |= REDRAW_INDEX;
1653 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1654 if (option (OPTRESOLVE)) {
1655 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1656 menu->current = menu->oldcurrent;
1657 menu->redraw = REDRAW_CURRENT;
1660 menu->redraw = REDRAW_MOTION_RESYNCH;
1663 menu->redraw = REDRAW_CURRENT;
1665 menu->redraw |= REDRAW_STATUS;
1674 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1677 for (j = 0; j < Context->vcount; j++) {
1678 if (Context->hdrs[Context->v2r[j]]->tagged) {
1679 if (Context->hdrs[Context->v2r[j]]->read ||
1680 Context->hdrs[Context->v2r[j]]->old)
1681 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1684 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1688 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1691 if (CURHDR->read || CURHDR->old)
1692 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1694 mutt_set_flag (Context, CURHDR, M_READ, 1);
1696 if (option (OPTRESOLVE)) {
1697 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1698 menu->current = menu->oldcurrent;
1699 menu->redraw = REDRAW_CURRENT;
1702 menu->redraw = REDRAW_MOTION_RESYNCH;
1705 menu->redraw = REDRAW_CURRENT;
1706 menu->redraw |= REDRAW_STATUS;
1710 case OP_TOGGLE_WRITE:
1713 if (mx_toggle_write (Context) == 0)
1714 menu->redraw |= REDRAW_STATUS;
1717 case OP_MAIN_NEXT_THREAD:
1718 case OP_MAIN_NEXT_SUBTHREAD:
1719 case OP_MAIN_PREV_THREAD:
1720 case OP_MAIN_PREV_SUBTHREAD:
1725 case OP_MAIN_NEXT_THREAD:
1726 menu->current = mutt_next_thread (CURHDR);
1729 case OP_MAIN_NEXT_SUBTHREAD:
1730 menu->current = mutt_next_subthread (CURHDR);
1733 case OP_MAIN_PREV_THREAD:
1734 menu->current = mutt_previous_thread (CURHDR);
1737 case OP_MAIN_PREV_SUBTHREAD:
1738 menu->current = mutt_previous_subthread (CURHDR);
1742 if (menu->current < 0) {
1743 menu->current = menu->oldcurrent;
1744 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1745 mutt_error (_("No more threads."));
1748 mutt_error (_("You are on the first thread."));
1750 else if (menu->menu == MENU_PAGER) {
1751 op = OP_DISPLAY_MESSAGE;
1755 menu->redraw = REDRAW_MOTION;
1758 case OP_MAIN_PARENT_MESSAGE:
1763 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1764 menu->current = menu->oldcurrent;
1766 else if (menu->menu == MENU_PAGER) {
1767 op = OP_DISPLAY_MESSAGE;
1771 menu->redraw = REDRAW_MOTION;
1774 case OP_MAIN_SET_FLAG:
1775 case OP_MAIN_CLEAR_FLAG:
1781 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1783 menu->redraw = REDRAW_STATUS;
1785 menu->redraw |= REDRAW_INDEX;
1786 else if (option (OPTRESOLVE)) {
1787 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1788 menu->current = menu->oldcurrent;
1789 menu->redraw |= REDRAW_CURRENT;
1792 menu->redraw |= REDRAW_MOTION_RESYNCH;
1795 menu->redraw |= REDRAW_CURRENT;
1799 case OP_MAIN_COLLAPSE_THREAD:
1803 if ((Sort & SORT_MASK) != SORT_THREADS) {
1804 mutt_error (_("Threading is not enabled."));
1809 if (CURHDR->collapsed) {
1810 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1811 mutt_set_virtual (Context);
1812 if (option (OPTUNCOLLAPSEJUMP))
1813 menu->current = mutt_thread_next_unread (Context, CURHDR);
1815 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1816 menu->current = mutt_collapse_thread (Context, CURHDR);
1817 mutt_set_virtual (Context);
1820 mutt_error (_("Thread contains unread messages."));
1825 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1829 case OP_MAIN_COLLAPSE_ALL:
1833 if ((Sort & SORT_MASK) != SORT_THREADS) {
1834 mutt_error (_("Threading is not enabled."));
1841 THREAD *thread, *top;
1844 if (CURHDR->collapsed)
1845 final = mutt_uncollapse_thread (Context, CURHDR);
1846 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1847 final = mutt_collapse_thread (Context, CURHDR);
1849 final = CURHDR->virtual;
1851 base = Context->hdrs[Context->v2r[final]];
1853 top = Context->tree;
1854 Context->collapsed = !Context->collapsed;
1855 while ((thread = top) != NULL) {
1856 while (!thread->message)
1857 thread = thread->child;
1858 h = thread->message;
1860 if (h->collapsed != Context->collapsed) {
1862 mutt_uncollapse_thread (Context, h);
1863 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1864 mutt_collapse_thread (Context, h);
1869 mutt_set_virtual (Context);
1870 for (j = 0; j < Context->vcount; j++) {
1871 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1877 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1881 /* --------------------------------------------------------------------
1882 * These functions are invoked directly from the internal-pager
1885 case OP_BOUNCE_MESSAGE:
1890 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1893 case OP_CREATE_ALIAS:
1895 mutt_create_alias (Context
1896 && Context->vcount ? CURHDR->env : NULL, NULL);
1897 MAYBE_REDRAW (menu->redraw);
1898 menu->redraw |= REDRAW_CURRENT;
1903 mutt_query_menu (NULL, 0);
1904 MAYBE_REDRAW (menu->redraw);
1907 case OP_PURGE_MESSAGE:
1914 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1917 mutt_tag_set_flag (M_DELETE, 1);
1918 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1919 if (option (OPTDELETEUNTAG))
1920 mutt_tag_set_flag (M_TAG, 0);
1921 menu->redraw = REDRAW_INDEX;
1924 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1925 mutt_set_flag (Context, CURHDR, M_PURGED,
1926 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1927 if (option (OPTDELETEUNTAG))
1928 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1929 if (option (OPTRESOLVE)) {
1930 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1931 menu->current = menu->oldcurrent;
1932 menu->redraw = REDRAW_CURRENT;
1934 else if (menu->menu == MENU_PAGER) {
1935 op = OP_DISPLAY_MESSAGE;
1939 menu->redraw |= REDRAW_MOTION_RESYNCH;
1942 menu->redraw = REDRAW_CURRENT;
1944 menu->redraw |= REDRAW_STATUS;
1947 case OP_DELETE_THREAD:
1948 case OP_DELETE_SUBTHREAD:
1954 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1956 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1957 op == OP_DELETE_THREAD ? 0 : 1);
1960 if (option (OPTDELETEUNTAG))
1961 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1962 op == OP_DELETE_THREAD ? 0 : 1);
1963 if (option (OPTRESOLVE))
1964 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1965 menu->current = menu->oldcurrent;
1966 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1972 if (Context && Context->magic == M_NNTP) {
1973 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1974 ((NNTP_DATA *) Context->data)->group))
1975 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1980 case OP_DISPLAY_ADDRESS:
1984 mutt_display_address (CURHDR->env);
1987 case OP_ENTER_COMMAND:
1989 CurrentMenu = MENU_MAIN;
1990 mutt_enter_command ();
1991 mutt_check_rescore (Context);
1992 if (option (OPTFORCEREDRAWINDEX))
1993 menu->redraw = REDRAW_FULL;
1994 unset_option (OPTFORCEREDRAWINDEX);
1995 unset_option (OPTFORCEREDRAWPAGER);
1998 case OP_EDIT_MESSAGE:
2005 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
2007 if (option (OPTPGPAUTODEC)
2008 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2009 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2010 mutt_edit_message (Context, tag ? NULL : CURHDR);
2011 menu->redraw = REDRAW_FULL;
2015 case OP_FORWARD_MESSAGE:
2021 if (option (OPTPGPAUTODEC) &&
2022 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2023 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2024 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2025 menu->redraw = REDRAW_FULL;
2029 case OP_FORGET_PASSPHRASE:
2030 crypt_forget_passphrase ();
2033 case OP_GROUP_REPLY:
2039 if (option (OPTPGPAUTODEC) &&
2040 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2041 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2043 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2044 tag ? NULL : CURHDR);
2045 menu->redraw = REDRAW_FULL;
2054 if (option (OPTPGPAUTODEC) &&
2055 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2056 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2058 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2059 tag ? NULL : CURHDR);
2060 menu->redraw = REDRAW_FULL;
2066 ci_send_message (0, NULL, NULL, Context, NULL);
2067 menu->redraw = REDRAW_FULL;
2072 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2073 menu->redraw = REDRAW_FULL;
2077 case OP_EXTRACT_KEYS:
2080 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2081 menu->redraw = REDRAW_FULL;
2085 case OP_CHECK_TRADITIONAL:
2088 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2089 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2091 if (menu->menu == MENU_PAGER) {
2092 op = OP_DISPLAY_MESSAGE;
2101 mutt_pipe_message (tag ? NULL : CURHDR);
2103 /* in an IMAP folder index with imap_peek=no, piping could change
2104 * * new or old messages status to read. Redraw what's needed.
2106 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2107 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2110 MAYBE_REDRAW (menu->redraw);
2117 mutt_print_message (tag ? NULL : CURHDR);
2119 /* in an IMAP folder index with imap_peek=no, piping could change
2120 * * new or old messages status to read. Redraw what's needed.
2122 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2123 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2128 case OP_MAIN_READ_THREAD:
2129 case OP_MAIN_READ_SUBTHREAD:
2135 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2137 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2138 op == OP_MAIN_READ_THREAD ? 0 : 1);
2141 if (option (OPTRESOLVE)) {
2142 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2143 mutt_next_thread (CURHDR) :
2144 mutt_next_subthread (CURHDR))) == -1)
2145 menu->current = menu->oldcurrent;
2147 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2151 case OP_RECALL_MESSAGE:
2154 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2155 menu->redraw = REDRAW_FULL;
2165 for (j = 0; j < Context->vcount; j++) {
2166 if (Context->hdrs[Context->v2r[j]]->tagged)
2167 mutt_resend_message (NULL, Context,
2168 Context->hdrs[Context->v2r[j]]);
2172 mutt_resend_message (NULL, Context, CURHDR);
2174 menu->redraw = REDRAW_FULL;
2180 case OP_FORWARD_TO_GROUP:
2183 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2184 Context && Context->msgcount == 0) {
2185 mutt_error (_("There are no messages."));
2188 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2189 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2190 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2191 _("Reply by mail as poster prefers?")) !=
2193 if (Context && Context->magic == M_NNTP
2194 && !((NNTP_DATA *) Context->data)->allowed
2195 && query_quadoption (OPT_TOMODERATED,
2197 ("Posting to this group not allowed, may be moderated. Continue?"))
2201 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2204 if (op == OP_FOLLOWUP)
2205 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2206 tag ? NULL : CURHDR);
2208 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2209 tag ? NULL : CURHDR);
2211 menu->redraw = REDRAW_FULL;
2222 if (option (OPTPGPAUTODEC) &&
2223 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2224 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2226 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2227 menu->redraw = REDRAW_FULL;
2230 case OP_SHELL_ESCAPE:
2232 mutt_shell_escape ();
2233 MAYBE_REDRAW (menu->redraw);
2237 case OP_TAG_SUBTHREAD:
2241 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2242 op == OP_TAG_THREAD ? 0 : 1);
2245 if (option (OPTRESOLVE)) {
2246 menu->current = mutt_next_thread (CURHDR);
2248 if (menu->current == -1)
2249 menu->current = menu->oldcurrent;
2251 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2261 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2264 mutt_tag_set_flag (M_DELETE, 0);
2265 mutt_tag_set_flag (M_PURGED, 0);
2266 menu->redraw = REDRAW_INDEX;
2269 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2270 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2271 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2273 menu->redraw = REDRAW_MOTION_RESYNCH;
2276 menu->redraw = REDRAW_CURRENT;
2278 menu->redraw |= REDRAW_STATUS;
2281 case OP_UNDELETE_THREAD:
2282 case OP_UNDELETE_SUBTHREAD:
2288 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2290 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2291 op == OP_UNDELETE_THREAD ? 0 : 1)
2292 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2293 op == OP_UNDELETE_THREAD ? 0 : 1);
2296 if (option (OPTRESOLVE)) {
2297 if (op == OP_UNDELETE_THREAD)
2298 menu->current = mutt_next_thread (CURHDR);
2300 menu->current = mutt_next_subthread (CURHDR);
2302 if (menu->current == -1)
2303 menu->current = menu->oldcurrent;
2305 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2314 if (option (OPTFORCEBUFFYCHECK))
2317 menu->redraw = REDRAW_FULL;
2320 case OP_VIEW_ATTACHMENTS:
2323 mutt_view_attachments (CURHDR);
2324 if (CURHDR->attach_del)
2325 Context->changed = 1;
2326 menu->redraw = REDRAW_FULL;
2336 case OP_REBUILD_CACHE:
2337 mx_rebuild_cache ();
2340 case OP_SIDEBAR_SCROLL_UP:
2341 case OP_SIDEBAR_SCROLL_DOWN:
2342 case OP_SIDEBAR_NEXT:
2343 case OP_SIDEBAR_PREV:
2344 case OP_SIDEBAR_NEXT_NEW:
2345 case OP_SIDEBAR_PREV_NEW:
2346 sidebar_scroll (op, menu->menu);
2349 if (menu->menu == MENU_MAIN)
2350 km_error_key (MENU_MAIN);
2353 if (menu->menu == MENU_PAGER) {
2354 menu->menu = MENU_MAIN;
2355 menu->redraw = REDRAW_FULL;
2357 set_option (OPTWEED); /* turn header weeding back on. */
2367 /* Close all open IMAP connections */
2371 /* Close all open NNTP connections */
2379 mutt_menuDestroy (&menu);
2383 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2390 for (color = ColorIndexList; color; color = color->next)
2391 if (mutt_pattern_exec
2392 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2393 curhdr->pair = color->pair;
2396 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];