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>
22 #include <lib-ui/curses.h>
28 #include "mutt_menu.h"
30 #include "recvattach.h"
37 #include <imap/imap_private.h>
39 #include <lib-crypt/crypt.h>
42 #include "nntp/nntp.h"
46 #include "mutt_sasl.h"
49 #include "lib/debug.h"
59 static const char *No_mailbox_is_open = N_("No mailbox is open.");
60 static const char *There_are_no_messages = N_("There are no messages.");
61 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
62 static const char *Function_not_permitted_in_attach_message_mode =
63 N_("Function not permitted in attach-message mode.");
64 static const char *No_visible = N_("No visible messages.");
66 #define CHECK_IN_MAILBOX if (!Context) \
69 mutt_error (_(No_mailbox_is_open)); \
73 #define CHECK_MSGCOUNT if (!Context) \
76 mutt_error(_(No_mailbox_is_open)); \
79 else if (!Context->msgcount) \
82 mutt_error(_(There_are_no_messages)); \
86 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
89 mutt_error(_(No_visible)); \
94 #define CHECK_READONLY if (Context->readonly) \
97 mutt_error(_(Mailbox_is_read_only)); \
101 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
104 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
108 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
109 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
110 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
111 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
113 extern size_t UngetCount;
115 void index_make_entry (char *s, ssize_t l, struct menu_t * menu, int num)
118 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
119 int edgemsgno, reverse = Sort & SORT_REVERSE;
120 HEADER *h = Context->hdrs[Context->v2r[num]];
123 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
124 flag |= M_FORMAT_TREE; /* display the thread tree */
125 if (h->display_subject)
126 flag |= M_FORMAT_FORCESUBJ;
129 if (menu->top + menu->pagelen > menu->max)
130 edgemsgno = Context->v2r[menu->max - 1];
132 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
135 edgemsgno = Context->v2r[menu->top];
137 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
141 /* if no ancestor is visible on current screen, provisionally force
143 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
145 flag |= M_FORMAT_FORCESUBJ;
148 else if (tmp->message->virtual >= 0)
151 if (flag & M_FORMAT_FORCESUBJ) {
152 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
156 /* ...but if a previous sibling is available, don't force it */
157 if (reverse ? tmp->message->msgno >
158 edgemsgno : tmp->message->msgno < edgemsgno)
160 else if (tmp->message->virtual >= 0) {
161 flag &= ~M_FORMAT_FORCESUBJ;
169 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
172 int index_color (int index_no)
174 HEADER *h = Context->hdrs[Context->v2r[index_no]];
179 mutt_set_header_color (Context, h);
183 static int ci_next_undeleted (int msgno)
187 for (i = msgno + 1; i < Context->vcount; i++)
188 if (!Context->hdrs[Context->v2r[i]]->deleted)
193 static int ci_previous_undeleted (int msgno)
197 for (i = msgno - 1; i >= 0; i--)
198 if (!Context->hdrs[Context->v2r[i]]->deleted)
203 /* Return the index of the first new message, or failing that, the first
206 static int ci_first_message (void)
210 if (Context && Context->msgcount) {
211 for (i = 0; i < Context->vcount; i++) {
212 if (!Context->hdrs[Context->v2r[i]]->read &&
213 !Context->hdrs[Context->v2r[i]]->deleted) {
214 if (!Context->hdrs[Context->v2r[i]]->old)
223 /* If Sort is reverse and not threaded, the latest message is first.
224 * If Sort is threaded, the latest message is first iff exactly one
225 * of Sort and SortAux are reverse.
227 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
228 ((Sort & SORT_MASK) == SORT_THREADS &&
229 ((Sort ^ SortAux) & SORT_REVERSE)))
232 return (Context->vcount ? Context->vcount - 1 : 0);
237 /* This should be in mx.c, but it only gets used here. */
238 static int mx_toggle_write (CONTEXT * ctx)
244 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
249 if (ctx->dontwrite) {
251 mutt_message (_("Changes to folder will be written on folder exit."));
255 mutt_message (_("Changes to folder will not be written."));
261 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
262 int oldcount, int index_hint)
264 /* store pointers to the newly added messages */
265 HEADER **save_new = NULL;
268 /* take note of the current message */
270 if (menu->current < Context->vcount)
271 menu->oldcurrent = index_hint;
273 oldcount = 0; /* invalid message number! */
276 /* We are in a limited view. Check if the new message(s) satisfy
277 * the limit criteria. If they do, set their virtual msgno so that
278 * they will be visible in the limited view */
279 if (Context->pattern) {
280 #define THIS_BODY Context->hdrs[j]->content
281 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
282 if (mutt_pattern_exec
283 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
285 Context->hdrs[j]->virtual = Context->vcount;
286 Context->v2r[Context->vcount] = j;
287 Context->hdrs[j]->limited = 1;
290 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
296 /* save the list of new messages */
297 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
298 save_new = p_new(HEADER*, Context->msgcount - oldcount);
299 for (j = oldcount; j < Context->msgcount; j++)
300 save_new[j - oldcount] = Context->hdrs[j];
303 /* if the mailbox was reopened, need to rethread from scratch */
304 mutt_sort_headers (Context, (check == M_REOPENED));
306 /* uncollapse threads with new mail */
307 if ((Sort & SORT_MASK) == SORT_THREADS) {
308 if (check == M_REOPENED) {
311 Context->collapsed = 0;
313 for (h = Context->tree; h; h = h->next) {
314 for (c = h; !c->message; c = c->child);
315 mutt_uncollapse_thread (Context, c->message);
317 mutt_set_virtual (Context);
320 for (j = 0; j < Context->msgcount - oldcount; j++) {
323 for (k = 0; k < Context->msgcount; k++) {
324 HEADER *h = Context->hdrs[k];
326 if (h == save_new[j] && (!Context->pattern || h->limited))
327 mutt_uncollapse_thread (Context, h);
331 mutt_set_virtual (Context);
337 /* restore the current message to the message it was pointing to */
338 for (j = 0; j < Context->vcount; j++) {
339 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
346 if (menu->current < 0)
347 menu->current = ci_first_message ();
350 static void resort_index (MUTTMENU * menu)
353 HEADER *current = CURHDR;
356 mutt_sort_headers (Context, 0);
357 /* Restore the current message */
359 for (i = 0; i < Context->vcount; i++) {
360 if (Context->hdrs[Context->v2r[i]] == current) {
366 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
367 menu->current = mutt_parent_message (Context, current);
369 if (menu->current < 0)
370 menu->current = ci_first_message ();
372 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
375 struct mapping_t IndexHelp[] = {
376 {N_("Quit"), OP_QUIT},
377 {N_("Del"), OP_DELETE},
378 {N_("Undel"), OP_UNDELETE},
379 {N_("Save"), OP_SAVE},
380 {N_("Mail"), OP_MAIL},
381 {N_("Reply"), OP_REPLY},
382 {N_("Group"), OP_GROUP_REPLY},
383 {N_("Help"), OP_HELP},
388 struct mapping_t IndexNewsHelp[] = {
389 {N_("Quit"), OP_QUIT},
390 {N_("Del"), OP_DELETE},
391 {N_("Undel"), OP_UNDELETE},
392 {N_("Save"), OP_SAVE},
393 {N_("Post"), OP_POST},
394 {N_("Followup"), OP_FOLLOWUP},
395 {N_("Catchup"), OP_CATCHUP},
396 {N_("Help"), OP_HELP},
401 /* This function handles the message index window as well as commands returned
402 * from the pager (MENU_PAGER).
404 int mutt_index_menu (void)
406 char buf[LONG_STRING], helpstr[SHORT_STRING];
409 int done = 0; /* controls when to exit the "event" loop */
411 int tag = 0; /* has the tag-prefix command been pressed? */
416 char *cp; /* temporary variable. */
417 int index_hint; /* used to restore cursor position */
418 int do_buffy_notify = 1;
419 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
420 int attach_msg = option (OPTATTACHMSG);
422 menu = mutt_new_menu ();
423 menu->menu = MENU_MAIN;
425 menu->pagelen = LINES - 3;
426 menu->make_entry = (void *) index_make_entry;
427 menu->color = index_color;
428 menu->current = ci_first_message ();
429 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
432 && (Context->magic ==
433 M_NNTP)) ? IndexNewsHelp :
438 buffy_check (0); /* force the buffy check after we enter the folder */
439 /* record folder we open to place sidebar indicator properly */
440 if (Context && Context->path)
441 sidebar_set_current (Context->path);
445 tag = 0; /* clear the tag-prefix */
447 menu->max = Context ? Context->vcount : 0;
448 oldcount = Context ? Context->msgcount : 0;
450 /* check if we need to resort the index because just about
451 * any 'op' below could do mutt_enter_command(), either here or
452 * from any new menu launched, and change $sort/$sort_aux
454 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
457 if (option (OPTREDRAWTREE) && Context && Context->msgcount
458 && (Sort & SORT_MASK) == SORT_THREADS) {
459 mutt_draw_tree (Context);
460 menu->redraw |= REDRAW_STATUS;
461 unset_option (OPTREDRAWTREE);
464 if (Context && !attach_msg) {
467 /* check for new mail in the mailbox. If nonzero, then something has
468 * changed about the file (either we got new mail or the file was
469 * modified underneath us.)
472 imap_allow_reopen (Context);
474 index_hint = (Context->vcount && menu->current >= 0
475 && menu->current < Context->vcount) ? CURHDR->index : 0;
477 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
478 if (!Context->path) {
479 /* fatal error occurred */
481 menu->redraw = REDRAW_FULL;
483 set_option (OPTSEARCHINVALID);
485 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
486 update_index (menu, Context, check, oldcount, index_hint);
488 /* notify the user of new mail */
489 if (check == M_REOPENED)
491 ("Mailbox was externally modified. Flags may be wrong."));
492 else if (check == M_NEW_MAIL) {
493 /* on new mail: redraw sidebar */
494 sidebar_draw (CurrentMenu);
495 mutt_message (_("New mail in this mailbox."));
497 if (option (OPTBEEPNEW))
500 else if (check == M_FLAGS)
501 mutt_message (_("Mailbox was externally modified."));
503 /* avoid the message being overwritten by buffy */
506 menu->redraw = REDRAW_FULL;
507 menu->max = Context->vcount;
509 set_option (OPTSEARCHINVALID);
514 imap_disallow_reopen (Context);
517 /* check for new mail in the incoming folders */
519 if ((newcount = buffy_check (0)) != oldcount) {
520 menu->redraw |= REDRAW_STATUS;
521 menu->redraw |= REDRAW_SIDEBAR;
523 if (do_buffy_notify) {
524 if (buffy_notify () && option (OPTBEEPNEW))
533 if (menu->redraw & REDRAW_SIDEBAR)
534 sidebar_draw (menu->menu);
535 if (menu->redraw & REDRAW_FULL) {
536 menu_redraw_full (menu);
537 sidebar_draw (menu->menu);
541 if (menu->menu == MENU_MAIN) {
542 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
543 menu_check_recenter (menu);
545 if (menu->redraw & REDRAW_INDEX) {
546 menu_redraw_index (menu);
547 menu->redraw |= REDRAW_STATUS;
549 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
550 menu_redraw_motion (menu);
551 else if (menu->redraw & REDRAW_CURRENT)
552 menu_redraw_current (menu);
555 if (menu->redraw & REDRAW_STATUS) {
556 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
557 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
558 sidebar_draw_frames();
559 SETCOLOR (MT_COLOR_STATUS);
560 BKGDSET (MT_COLOR_STATUS);
561 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
562 mutt_paddstr (COLS-SW, buf);
563 SETCOLOR (MT_COLOR_NORMAL);
564 BKGDSET (MT_COLOR_NORMAL);
565 sidebar_set_buffystats (Context);
566 menu->redraw &= ~REDRAW_STATUS;
567 if (option (OPTXTERMSETTITLES)) {
568 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
569 mutt_xterm_set_title (buf);
570 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
571 mutt_xterm_set_icon (buf);
576 if (menu->current < menu->max)
577 menu->oldcurrent = menu->current;
579 menu->oldcurrent = -1;
581 if (option (OPTARROWCURSOR))
582 move (menu->current - menu->top + menu->offset, 2);
583 else if (option (OPTBRAILLEFRIENDLY))
584 move (menu->current - menu->top + menu->offset, 0);
586 move (menu->current - menu->top + menu->offset, COLS - 1);
589 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
592 mutt_resize_screen ();
593 menu->redraw = REDRAW_FULL;
594 menu->menu = MENU_MAIN;
596 menu->top = 0; /* so we scroll the right amount */
598 * force a real complete redraw. clrtobot() doesn't seem to be able
599 * to handle every case without this.
601 clearok (stdscr, TRUE);
606 op = km_dokey (MENU_MAIN);
608 debug_print (4, ("Got op %d\n", op));
611 continue; /* either user abort or timeout */
615 /* special handling for the tag-prefix function */
616 if (op == OP_TAG_PREFIX) {
618 mutt_error (_("No mailbox is open."));
623 if (!Context->tagged) {
624 mutt_error (_("No tagged messages."));
630 /* give visual indication that the next command is a tag- command */
631 mvaddstr (LINES - 1, 0, "tag-");
634 /* get the real command */
635 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
636 /* abort tag sequence */
637 CLEARLINE (LINES - 1);
641 else if (option (OPTAUTOTAG) && Context && Context->tagged)
644 if (op == OP_TAG_PREFIX_COND) {
646 mutt_error (_("No mailbox is open."));
651 if (!Context->tagged) {
654 while (UngetCount > 0) {
656 if (tmp.op == OP_END_COND)
659 mutt_message (_("Nothing to do."));
665 /* give visual indication that the next command is a tag- command */
666 mvaddstr (LINES - 1, 0, "tag-");
669 /* get the real command */
670 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
671 /* abort tag sequence */
672 CLEARLINE (LINES - 1);
680 if (menu->current < menu->max)
681 menu->oldcurrent = menu->current;
683 menu->oldcurrent = -1;
685 mutt_curs_set (1); /* fallback from the pager */
689 unset_option (OPTNEWS); /* for any case */
694 /* ----------------------------------------------------------------------
699 menu_bottom_page (menu);
702 menu_first_entry (menu);
705 menu_middle_page (menu);
711 menu_half_down (menu);
714 menu_next_line (menu);
717 menu_prev_line (menu);
720 menu_next_page (menu);
723 menu_prev_page (menu);
726 menu_last_entry (menu);
729 menu_top_page (menu);
732 menu_current_top (menu);
734 case OP_CURRENT_MIDDLE:
735 menu_current_middle (menu);
737 case OP_CURRENT_BOTTOM:
738 menu_current_bottom (menu);
745 if (Context->magic == M_NNTP) {
748 if (op == OP_GET_MESSAGE) {
750 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
755 LIST *ref = CURHDR->env->references;
758 mutt_error (_("Article has no parent reference!"));
762 m_strcpy(buf, sizeof(buf), ref->data);
764 if (!Context->id_hash)
765 Context->id_hash = mutt_make_id_hash (Context);
766 if ((h = hash_find (Context->id_hash, buf))) {
767 if (h->virtual != -1) {
768 menu->current = h->virtual;
769 menu->redraw = REDRAW_MOTION_RESYNCH;
771 else if (h->collapsed) {
772 mutt_uncollapse_thread (Context, h);
773 mutt_set_virtual (Context);
774 menu->current = h->virtual;
775 menu->redraw = REDRAW_MOTION_RESYNCH;
778 mutt_error (_("Message not visible in limited view."));
781 if (nntp_check_msgid (Context, buf) == 0) {
782 h = Context->hdrs[Context->msgcount - 1];
783 mutt_sort_headers (Context, 0);
784 menu->current = h->virtual;
785 menu->redraw = REDRAW_FULL;
788 mutt_error (_("Article %s not found on server"), buf);
793 case OP_GET_CHILDREN:
794 case OP_RECONSTRUCT_THREAD:
796 if (Context->magic == M_NNTP) {
798 int old = CURHDR->index;
800 if (!CURHDR->env->message_id) {
801 mutt_error (_("No Message-ID. Unable to perform operation"));
806 if (!Context->id_hash)
807 Context->id_hash = mutt_make_id_hash (Context);
808 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
810 if (op == OP_RECONSTRUCT_THREAD) {
811 LIST *ref = CURHDR->env->references;
814 nntp_check_msgid (Context, ref->data);
815 /* the last msgid in References is the root message */
817 m_strcpy(buf, sizeof(buf), ref->data);
821 mutt_message (_("Check for children of message..."));
823 if (nntp_check_children (Context, buf) == 0) {
824 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
825 h = hash_find (Context->id_hash, buf);
826 /* if the root message was retrieved, move to it */
828 menu->current = h->virtual;
829 else /* try to restore old position */
830 for (i = 0; i < Context->msgcount; i++)
831 if (Context->hdrs[i]->index == old) {
832 menu->current = Context->hdrs[i]->virtual;
833 /* As an added courtesy, recenter the menu
834 * with the current entry at the middle of the screen */
835 menu_check_recenter (menu);
836 menu_current_middle (menu);
839 menu->redraw = REDRAW_FULL;
849 if (isdigit (LastKey))
850 mutt_ungetch (LastKey, 0);
852 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
856 if (!isdigit ((unsigned char) buf[0])) {
857 mutt_error (_("Argument must be a message number."));
863 if (i > 0 && i <= Context->msgcount) {
864 for (j = i - 1; j < Context->msgcount; j++) {
865 if (Context->hdrs[j]->virtual != -1)
868 if (j >= Context->msgcount) {
869 for (j = i - 2; j >= 0; j--) {
870 if (Context->hdrs[j]->virtual != -1)
876 menu->current = Context->hdrs[j]->virtual;
877 if (menu->menu == MENU_PAGER) {
878 op = OP_DISPLAY_MESSAGE;
882 menu->redraw = REDRAW_MOTION;
885 mutt_error (_("That message is not visible."));
888 mutt_error (_("Invalid message number."));
892 /* --------------------------------------------------------------------
893 * `index' specific commands
896 case OP_MAIN_DELETE_PATTERN:
902 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
905 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
906 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
909 case OP_MAIN_FETCH_MAIL:
913 menu->redraw = REDRAW_FULL;
918 mutt_help (MENU_MAIN);
919 menu->redraw = REDRAW_FULL;
922 case OP_MAIN_SHOW_LIMIT:
924 if (!Context->pattern)
925 mutt_message (_("No limit pattern is in effect."));
930 /* i18n: ask for a limit to apply */
931 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
932 mutt_message ("%s", buffer);
940 menu->oldcurrent = (Context->vcount && menu->current >= 0
942 Context->vcount) ? CURHDR->index : -1;
943 if (op == OP_TOGGLE_READ) {
944 char buffer[LONG_STRING];
946 if (!Context->pattern
947 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
948 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
949 Context->pattern ? Context->pattern : ".*");
950 set_option (OPTHIDEREAD);
953 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
954 if (!*buf || strncmp (buf, ".*", 2) == 0)
955 snprintf (buf, sizeof (buf), "~A");
956 unset_option (OPTHIDEREAD);
958 p_delete(&Context->pattern);
959 Context->pattern = m_strdup(buf);
961 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
962 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
964 if (menu->oldcurrent >= 0) {
965 /* try to find what used to be the current message */
967 for (i = 0; i < Context->vcount; i++)
968 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
972 if (menu->current < 0)
977 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
978 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
979 mutt_draw_tree (Context);
980 menu->redraw = REDRAW_FULL;
982 if (Context->pattern)
983 mutt_message _("To view all messages, limit to \"all\".");
994 if (query_quadoption (OPT_QUIT, _("Quit Madmutt?")) == M_YES) {
997 oldcount = Context ? Context->msgcount : 0;
1000 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1003 if (check == M_NEW_MAIL || check == M_REOPENED)
1004 update_index (menu, Context, check, oldcount, index_hint);
1006 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1007 set_option (OPTSEARCHINVALID);
1014 clearok (stdscr, TRUE);
1015 menu->redraw = REDRAW_FULL;
1019 case OP_SEARCH_REVERSE:
1020 case OP_SEARCH_NEXT:
1021 case OP_SEARCH_OPPOSITE:
1025 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1026 menu->current = menu->oldcurrent;
1028 menu->redraw = REDRAW_MOTION;
1032 case OP_SORT_REVERSE:
1034 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1035 if (Context && Context->msgcount) {
1036 resort_index (menu);
1037 set_option (OPTSEARCHINVALID);
1046 if (tag && !option (OPTAUTOTAG)) {
1047 for (j = 0; j < Context->vcount; j++)
1048 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1049 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1052 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1053 Context->last_tag = CURHDR->tagged ? CURHDR :
1054 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1055 ? NULL : Context->last_tag);
1056 menu->redraw = REDRAW_STATUS;
1057 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1059 menu->redraw |= REDRAW_MOTION_RESYNCH;
1062 menu->redraw |= REDRAW_CURRENT;
1066 case OP_MAIN_TAG_PATTERN:
1070 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1071 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1074 case OP_MAIN_UNDELETE_PATTERN:
1080 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1082 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1084 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1087 case OP_MAIN_UNTAG_PATTERN:
1091 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1092 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1095 /* --------------------------------------------------------------------
1096 * The following operations can be performed inside of the pager.
1099 case OP_MAIN_IMAP_FETCH:
1100 if (Context->magic == M_IMAP)
1101 imap_check_mailbox (Context, &index_hint, 1);
1104 case OP_MAIN_SYNC_FOLDER:
1106 if (Context && !Context->msgcount)
1113 int oldvcount = Context->vcount;
1114 oldcount = Context->msgcount;
1118 /* calculate the number of messages _above_ the cursor,
1119 * so we can keep the cursor on the current message
1121 for (j = 0; j <= menu->current; j++) {
1122 if (Context->hdrs[Context->v2r[j]]->deleted)
1126 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1127 if (Context->vcount != oldvcount)
1128 menu->current -= dcount;
1129 set_option (OPTSEARCHINVALID);
1131 else if (check == M_NEW_MAIL || check == M_REOPENED)
1132 update_index (menu, Context, check, oldcount, index_hint);
1135 * do a sanity check even if mx_sync_mailbox failed.
1138 if (menu->current < 0 || menu->current >= Context->vcount)
1139 menu->current = ci_first_message ();
1142 /* check for a fatal error, or all messages deleted */
1146 /* if we were in the pager, redisplay the message */
1147 if (menu->menu == MENU_PAGER) {
1148 op = OP_DISPLAY_MESSAGE;
1152 menu->redraw = REDRAW_FULL;
1155 case OP_SIDEBAR_OPEN:
1156 case OP_MAIN_CHANGE_FOLDER:
1157 case OP_MAIN_CHANGE_FOLDER_READONLY:
1159 case OP_MAIN_CHANGE_GROUP:
1160 case OP_MAIN_CHANGE_GROUP_READONLY:
1162 if (attach_msg || option (OPTREADONLY) ||
1164 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1166 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1172 cp = _("Open mailbox in read-only mode");
1174 cp = _("Open mailbox");
1178 unset_option (OPTNEWS);
1179 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1180 set_option (OPTNEWS);
1181 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1184 cp = _("Open newsgroup in read-only mode");
1186 cp = _("Open newsgroup");
1187 nntp_buffy (buf, sizeof (buf));
1192 if (Context && Context->path)
1193 m_strcpy(buf, sizeof(buf), Context->path);
1194 if (op != OP_SIDEBAR_OPEN)
1195 buffy_next (buf, sizeof (buf));
1198 if (op == OP_SIDEBAR_OPEN) {
1199 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1201 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1202 if (menu->menu == MENU_PAGER) {
1203 op = OP_DISPLAY_MESSAGE;
1209 CLEARLINE (LINES - 1);
1214 if (option (OPTNEWS)) {
1215 unset_option (OPTNEWS);
1216 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1220 mutt_expand_path (buf, sizeof (buf));
1221 if (mx_get_magic (buf) <= 0) {
1222 mutt_error (_("%s is not a mailbox."), buf);
1225 m_strreplace(&CurrentFolder, buf);
1230 if (Context->compressinfo && Context->realpath)
1231 m_strreplace(&LastFolder, Context->realpath);
1233 m_strreplace(&LastFolder, Context->path);
1234 oldcount = Context ? Context->msgcount : 0;
1236 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1237 if (check == M_NEW_MAIL || check == M_REOPENED)
1238 update_index (menu, Context, check, oldcount, index_hint);
1240 set_option (OPTSEARCHINVALID);
1241 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1249 /* Set CurrentMenu to MENU_MAIN before executing any folder
1250 * hooks so that all the index menu functions are available to
1254 CurrentMenu = MENU_MAIN;
1255 mutt_folder_hook (buf);
1257 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1258 menu->current = ci_first_message ();
1262 sidebar_set_current (buf);
1265 /* buffy_check() must be done with mail-reader mode! */
1266 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1268 && (Context->magic ==
1269 M_NNTP)) ? IndexNewsHelp :
1272 mutt_clear_error ();
1273 buffy_check (0); /* force the buffy check after we have changed
1275 menu->redraw = REDRAW_FULL;
1276 set_option (OPTSEARCHINVALID);
1279 case OP_DISPLAY_MESSAGE:
1280 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1285 * toggle the weeding of headers so that a user can press the key
1286 * again while reading the message.
1288 if (op == OP_DISPLAY_HEADERS)
1289 toggle_option (OPTWEED);
1291 unset_option (OPTNEEDRESORT);
1293 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1294 mutt_uncollapse_thread (Context, CURHDR);
1295 mutt_set_virtual (Context);
1296 if (option (OPTUNCOLLAPSEJUMP))
1297 menu->current = mutt_thread_next_unread (Context, CURHDR);
1300 if (option (OPTPGPAUTODEC) &&
1301 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1302 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1304 if ((op = mutt_display_message (CURHDR)) == -1) {
1305 unset_option (OPTNEEDRESORT);
1309 menu->menu = MENU_PAGER;
1310 menu->oldcurrent = menu->current;
1316 if (menu->menu == MENU_MAIN && attach_msg) {
1321 if ((menu->menu == MENU_MAIN)
1322 && (query_quadoption (OPT_QUIT,
1323 _("Exit Madmutt without saving?")) == M_YES))
1326 mx_fastclose_mailbox (Context);
1338 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1339 /* if we were in the pager, redisplay the message */
1340 if (menu->menu == MENU_PAGER) {
1341 op = OP_DISPLAY_MESSAGE;
1345 menu->redraw = REDRAW_CURRENT;
1348 case OP_MAIN_BREAK_THREAD:
1354 if ((Sort & SORT_MASK) != SORT_THREADS)
1355 mutt_error (_("Threading is not enabled."));
1359 HEADER *oldcur = CURHDR;
1361 mutt_break_thread (CURHDR);
1362 mutt_sort_headers (Context, 1);
1363 menu->current = oldcur->virtual;
1366 Context->changed = 1;
1367 mutt_message _("Thread broken");
1369 if (menu->menu == MENU_PAGER) {
1370 op = OP_DISPLAY_MESSAGE;
1374 menu->redraw |= REDRAW_INDEX;
1378 case OP_MAIN_LINK_THREADS:
1384 if ((Sort & SORT_MASK) != SORT_THREADS)
1385 mutt_error (_("Threading is not enabled."));
1387 else if (!CURHDR->env->message_id)
1388 mutt_error (_("No Message-ID: header available to link thread"));
1390 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1391 mutt_error (_("First, please tag a message to be linked here"));
1394 HEADER *oldcur = CURHDR;
1396 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1398 mutt_sort_headers (Context, 1);
1399 menu->current = oldcur->virtual;
1401 Context->changed = 1;
1402 mutt_message _("Threads linked");
1405 mutt_error (_("No thread linked"));
1408 if (menu->menu == MENU_PAGER) {
1409 op = OP_DISPLAY_MESSAGE;
1413 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1416 case OP_MAIN_NEXT_UNDELETED:
1420 if (menu->current >= Context->vcount - 1) {
1421 if (menu->menu == MENU_MAIN)
1422 mutt_error (_("You are on the last message."));
1426 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1427 menu->current = menu->oldcurrent;
1428 if (menu->menu == MENU_MAIN)
1429 mutt_error (_("No undeleted messages."));
1431 else if (menu->menu == MENU_PAGER) {
1432 op = OP_DISPLAY_MESSAGE;
1436 menu->redraw = REDRAW_MOTION;
1443 if (menu->current >= Context->vcount - 1) {
1444 if (menu->menu == MENU_MAIN)
1445 mutt_error (_("You are on the last message."));
1450 if (menu->menu == MENU_PAGER) {
1451 op = OP_DISPLAY_MESSAGE;
1455 menu->redraw = REDRAW_MOTION;
1458 case OP_MAIN_PREV_UNDELETED:
1462 if (menu->current < 1) {
1463 mutt_error (_("You are on the first message."));
1467 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1468 menu->current = menu->oldcurrent;
1469 if (menu->menu == MENU_MAIN)
1470 mutt_error (_("No undeleted messages."));
1472 else if (menu->menu == MENU_PAGER) {
1473 op = OP_DISPLAY_MESSAGE;
1477 menu->redraw = REDRAW_MOTION;
1484 if (menu->current < 1) {
1485 if (menu->menu == MENU_MAIN)
1486 mutt_error (_("You are on the first message."));
1491 if (menu->menu == MENU_PAGER) {
1492 op = OP_DISPLAY_MESSAGE;
1496 menu->redraw = REDRAW_MOTION;
1499 case OP_DECRYPT_COPY:
1500 case OP_DECRYPT_SAVE:
1501 case OP_COPY_MESSAGE:
1503 case OP_DECODE_COPY:
1504 case OP_DECODE_SAVE:
1507 if (mutt_save_message (tag ? NULL : CURHDR,
1508 (op == OP_DECRYPT_SAVE) ||
1509 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1510 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1511 (op == OP_DECRYPT_SAVE)
1512 || (op == OP_DECRYPT_COPY)
1513 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1520 menu->redraw |= REDRAW_INDEX;
1521 else if (option (OPTRESOLVE)) {
1522 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1523 menu->current = menu->oldcurrent;
1524 menu->redraw |= REDRAW_CURRENT;
1527 menu->redraw |= REDRAW_MOTION_RESYNCH;
1530 menu->redraw |= REDRAW_CURRENT;
1534 case OP_MAIN_NEXT_NEW:
1535 case OP_MAIN_NEXT_UNREAD:
1536 case OP_MAIN_PREV_NEW:
1537 case OP_MAIN_PREV_UNREAD:
1538 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1539 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1542 int first_unread = -1;
1550 for (j = 0; j != Context->vcount; j++) {
1551 #define CURHDRi Context->hdrs[Context->v2r[i]]
1552 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1553 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1555 if (i > Context->vcount - 1) {
1556 mutt_message _("Search wrapped to top.");
1564 mutt_message _("Search wrapped to bottom.");
1566 i = Context->vcount - 1;
1570 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1571 if (UNREAD (CURHDRi) && first_unread == -1)
1573 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1576 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1577 if (first_unread == -1)
1579 if ((!CURHDRi->old) && first_new == -1)
1583 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1586 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1587 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1588 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1593 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1594 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1595 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1597 menu->current = first_new;
1598 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1599 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1600 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1601 && first_unread != -1)
1602 menu->current = first_unread;
1604 if (menu->current == -1) {
1605 menu->current = menu->oldcurrent;
1606 mutt_error ("%s%s.",
1607 (op == OP_MAIN_NEXT_NEW
1609 OP_MAIN_PREV_NEW) ? _("No new messages") :
1610 _("No unread messages"),
1611 Context->pattern ? _(" in this limited view") : "");
1613 else if (menu->menu == MENU_PAGER) {
1614 op = OP_DISPLAY_MESSAGE;
1618 menu->redraw = REDRAW_MOTION;
1621 case OP_FLAG_MESSAGE:
1627 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1630 for (j = 0; j < Context->vcount; j++) {
1631 if (Context->hdrs[Context->v2r[j]]->tagged)
1632 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1633 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1636 menu->redraw |= REDRAW_INDEX;
1639 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1640 if (option (OPTRESOLVE)) {
1641 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1642 menu->current = menu->oldcurrent;
1643 menu->redraw = REDRAW_CURRENT;
1646 menu->redraw = REDRAW_MOTION_RESYNCH;
1649 menu->redraw = REDRAW_CURRENT;
1651 menu->redraw |= REDRAW_STATUS;
1660 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1663 for (j = 0; j < Context->vcount; j++) {
1664 if (Context->hdrs[Context->v2r[j]]->tagged) {
1665 if (Context->hdrs[Context->v2r[j]]->read ||
1666 Context->hdrs[Context->v2r[j]]->old)
1667 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1670 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1674 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1677 if (CURHDR->read || CURHDR->old)
1678 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1680 mutt_set_flag (Context, CURHDR, M_READ, 1);
1682 if (option (OPTRESOLVE)) {
1683 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1684 menu->current = menu->oldcurrent;
1685 menu->redraw = REDRAW_CURRENT;
1688 menu->redraw = REDRAW_MOTION_RESYNCH;
1691 menu->redraw = REDRAW_CURRENT;
1692 menu->redraw |= REDRAW_STATUS;
1696 case OP_TOGGLE_WRITE:
1699 if (mx_toggle_write (Context) == 0)
1700 menu->redraw |= REDRAW_STATUS;
1703 case OP_MAIN_NEXT_THREAD:
1704 case OP_MAIN_NEXT_SUBTHREAD:
1705 case OP_MAIN_PREV_THREAD:
1706 case OP_MAIN_PREV_SUBTHREAD:
1711 case OP_MAIN_NEXT_THREAD:
1712 menu->current = mutt_next_thread (CURHDR);
1715 case OP_MAIN_NEXT_SUBTHREAD:
1716 menu->current = mutt_next_subthread (CURHDR);
1719 case OP_MAIN_PREV_THREAD:
1720 menu->current = mutt_previous_thread (CURHDR);
1723 case OP_MAIN_PREV_SUBTHREAD:
1724 menu->current = mutt_previous_subthread (CURHDR);
1728 if (menu->current < 0) {
1729 menu->current = menu->oldcurrent;
1730 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1731 mutt_error (_("No more threads."));
1734 mutt_error (_("You are on the first thread."));
1736 else if (menu->menu == MENU_PAGER) {
1737 op = OP_DISPLAY_MESSAGE;
1741 menu->redraw = REDRAW_MOTION;
1744 case OP_MAIN_PARENT_MESSAGE:
1749 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1750 menu->current = menu->oldcurrent;
1752 else if (menu->menu == MENU_PAGER) {
1753 op = OP_DISPLAY_MESSAGE;
1757 menu->redraw = REDRAW_MOTION;
1760 case OP_MAIN_SET_FLAG:
1761 case OP_MAIN_CLEAR_FLAG:
1767 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1769 menu->redraw = REDRAW_STATUS;
1771 menu->redraw |= REDRAW_INDEX;
1772 else if (option (OPTRESOLVE)) {
1773 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1774 menu->current = menu->oldcurrent;
1775 menu->redraw |= REDRAW_CURRENT;
1778 menu->redraw |= REDRAW_MOTION_RESYNCH;
1781 menu->redraw |= REDRAW_CURRENT;
1785 case OP_MAIN_COLLAPSE_THREAD:
1789 if ((Sort & SORT_MASK) != SORT_THREADS) {
1790 mutt_error (_("Threading is not enabled."));
1795 if (CURHDR->collapsed) {
1796 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1797 mutt_set_virtual (Context);
1798 if (option (OPTUNCOLLAPSEJUMP))
1799 menu->current = mutt_thread_next_unread (Context, CURHDR);
1801 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1802 menu->current = mutt_collapse_thread (Context, CURHDR);
1803 mutt_set_virtual (Context);
1806 mutt_error (_("Thread contains unread messages."));
1811 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1815 case OP_MAIN_COLLAPSE_ALL:
1819 if ((Sort & SORT_MASK) != SORT_THREADS) {
1820 mutt_error (_("Threading is not enabled."));
1827 THREAD *thread, *top;
1830 if (CURHDR->collapsed)
1831 final = mutt_uncollapse_thread (Context, CURHDR);
1832 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1833 final = mutt_collapse_thread (Context, CURHDR);
1835 final = CURHDR->virtual;
1837 base = Context->hdrs[Context->v2r[final]];
1839 top = Context->tree;
1840 Context->collapsed = !Context->collapsed;
1841 while ((thread = top) != NULL) {
1842 while (!thread->message)
1843 thread = thread->child;
1844 h = thread->message;
1846 if (h->collapsed != Context->collapsed) {
1848 mutt_uncollapse_thread (Context, h);
1849 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1850 mutt_collapse_thread (Context, h);
1855 mutt_set_virtual (Context);
1856 for (j = 0; j < Context->vcount; j++) {
1857 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1863 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1867 /* --------------------------------------------------------------------
1868 * These functions are invoked directly from the internal-pager
1871 case OP_BOUNCE_MESSAGE:
1876 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1879 case OP_CREATE_ALIAS:
1881 mutt_create_alias (Context
1882 && Context->vcount ? CURHDR->env : NULL, NULL);
1883 MAYBE_REDRAW (menu->redraw);
1884 menu->redraw |= REDRAW_CURRENT;
1889 mutt_query_menu (NULL, 0);
1890 MAYBE_REDRAW (menu->redraw);
1893 case OP_PURGE_MESSAGE:
1900 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1903 mutt_tag_set_flag (M_DELETE, 1);
1904 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1905 if (option (OPTDELETEUNTAG))
1906 mutt_tag_set_flag (M_TAG, 0);
1907 menu->redraw = REDRAW_INDEX;
1910 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1911 mutt_set_flag (Context, CURHDR, M_PURGED,
1912 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1913 if (option (OPTDELETEUNTAG))
1914 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1915 if (option (OPTRESOLVE)) {
1916 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1917 menu->current = menu->oldcurrent;
1918 menu->redraw = REDRAW_CURRENT;
1920 else if (menu->menu == MENU_PAGER) {
1921 op = OP_DISPLAY_MESSAGE;
1925 menu->redraw |= REDRAW_MOTION_RESYNCH;
1928 menu->redraw = REDRAW_CURRENT;
1930 menu->redraw |= REDRAW_STATUS;
1933 case OP_DELETE_THREAD:
1934 case OP_DELETE_SUBTHREAD:
1940 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1942 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1943 op == OP_DELETE_THREAD ? 0 : 1);
1946 if (option (OPTDELETEUNTAG))
1947 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1948 op == OP_DELETE_THREAD ? 0 : 1);
1949 if (option (OPTRESOLVE))
1950 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1951 menu->current = menu->oldcurrent;
1952 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1958 if (Context && Context->magic == M_NNTP) {
1959 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1960 ((NNTP_DATA *) Context->data)->group))
1961 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1966 case OP_DISPLAY_ADDRESS:
1970 mutt_display_address (CURHDR->env);
1973 case OP_ENTER_COMMAND:
1975 CurrentMenu = MENU_MAIN;
1976 mutt_enter_command ();
1977 mutt_check_rescore (Context);
1978 if (option (OPTFORCEREDRAWINDEX))
1979 menu->redraw = REDRAW_FULL;
1980 unset_option (OPTFORCEREDRAWINDEX);
1981 unset_option (OPTFORCEREDRAWPAGER);
1984 case OP_EDIT_MESSAGE:
1991 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1993 if (option (OPTPGPAUTODEC)
1994 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1995 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1996 mutt_edit_message (Context, tag ? NULL : CURHDR);
1997 menu->redraw = REDRAW_FULL;
2001 case OP_FORWARD_MESSAGE:
2007 if (option (OPTPGPAUTODEC) &&
2008 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2009 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2010 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2011 menu->redraw = REDRAW_FULL;
2015 case OP_FORGET_PASSPHRASE:
2016 crypt_forget_passphrase ();
2019 case OP_GROUP_REPLY:
2025 if (option (OPTPGPAUTODEC) &&
2026 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2027 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2029 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2030 tag ? NULL : CURHDR);
2031 menu->redraw = REDRAW_FULL;
2040 if (option (OPTPGPAUTODEC) &&
2041 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2042 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2044 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2045 tag ? NULL : CURHDR);
2046 menu->redraw = REDRAW_FULL;
2052 ci_send_message (0, NULL, NULL, Context, NULL);
2053 menu->redraw = REDRAW_FULL;
2058 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2059 menu->redraw = REDRAW_FULL;
2063 case OP_EXTRACT_KEYS:
2066 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2067 menu->redraw = REDRAW_FULL;
2071 case OP_CHECK_TRADITIONAL:
2074 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2075 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2077 if (menu->menu == MENU_PAGER) {
2078 op = OP_DISPLAY_MESSAGE;
2087 mutt_pipe_message (tag ? NULL : CURHDR);
2088 /* in an IMAP folder index with imap_peek=no, piping could change
2089 * * new or old messages status to read. Redraw what's needed.
2091 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2092 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2094 MAYBE_REDRAW (menu->redraw);
2101 mutt_print_message (tag ? NULL : CURHDR);
2102 /* in an IMAP folder index with imap_peek=no, piping could change
2103 * * new or old messages status to read. Redraw what's needed.
2105 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2106 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2110 case OP_MAIN_READ_THREAD:
2111 case OP_MAIN_READ_SUBTHREAD:
2117 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2119 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2120 op == OP_MAIN_READ_THREAD ? 0 : 1);
2123 if (option (OPTRESOLVE)) {
2124 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2125 mutt_next_thread (CURHDR) :
2126 mutt_next_subthread (CURHDR))) == -1)
2127 menu->current = menu->oldcurrent;
2129 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2133 case OP_RECALL_MESSAGE:
2136 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2137 menu->redraw = REDRAW_FULL;
2147 for (j = 0; j < Context->vcount; j++) {
2148 if (Context->hdrs[Context->v2r[j]]->tagged)
2149 mutt_resend_message (NULL, Context,
2150 Context->hdrs[Context->v2r[j]]);
2154 mutt_resend_message (NULL, Context, CURHDR);
2156 menu->redraw = REDRAW_FULL;
2162 case OP_FORWARD_TO_GROUP:
2165 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2166 Context && Context->msgcount == 0) {
2167 mutt_error (_("There are no messages."));
2170 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2171 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2172 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2173 _("Reply by mail as poster prefers?")) !=
2175 if (Context && Context->magic == M_NNTP
2176 && !((NNTP_DATA *) Context->data)->allowed
2177 && query_quadoption (OPT_TOMODERATED,
2179 ("Posting to this group not allowed, may be moderated. Continue?"))
2183 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2186 if (op == OP_FOLLOWUP)
2187 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2188 tag ? NULL : CURHDR);
2190 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2191 tag ? NULL : CURHDR);
2193 menu->redraw = REDRAW_FULL;
2204 if (option (OPTPGPAUTODEC) &&
2205 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2206 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2208 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2209 menu->redraw = REDRAW_FULL;
2212 case OP_SHELL_ESCAPE:
2214 mutt_shell_escape ();
2215 MAYBE_REDRAW (menu->redraw);
2219 case OP_TAG_SUBTHREAD:
2223 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2224 op == OP_TAG_THREAD ? 0 : 1);
2227 if (option (OPTRESOLVE)) {
2228 menu->current = mutt_next_thread (CURHDR);
2230 if (menu->current == -1)
2231 menu->current = menu->oldcurrent;
2233 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2243 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2246 mutt_tag_set_flag (M_DELETE, 0);
2247 mutt_tag_set_flag (M_PURGED, 0);
2248 menu->redraw = REDRAW_INDEX;
2251 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2252 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2253 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2255 menu->redraw = REDRAW_MOTION_RESYNCH;
2258 menu->redraw = REDRAW_CURRENT;
2260 menu->redraw |= REDRAW_STATUS;
2263 case OP_UNDELETE_THREAD:
2264 case OP_UNDELETE_SUBTHREAD:
2270 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2272 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2273 op == OP_UNDELETE_THREAD ? 0 : 1)
2274 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2275 op == OP_UNDELETE_THREAD ? 0 : 1);
2278 if (option (OPTRESOLVE)) {
2279 if (op == OP_UNDELETE_THREAD)
2280 menu->current = mutt_next_thread (CURHDR);
2282 menu->current = mutt_next_subthread (CURHDR);
2284 if (menu->current == -1)
2285 menu->current = menu->oldcurrent;
2287 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2296 if (option (OPTFORCEBUFFYCHECK))
2299 menu->redraw = REDRAW_FULL;
2302 case OP_VIEW_ATTACHMENTS:
2305 mutt_view_attachments (CURHDR);
2306 if (CURHDR->attach_del)
2307 Context->changed = 1;
2308 menu->redraw = REDRAW_FULL;
2318 case OP_REBUILD_CACHE:
2319 mx_rebuild_cache ();
2322 case OP_SIDEBAR_SCROLL_UP:
2323 case OP_SIDEBAR_SCROLL_DOWN:
2324 case OP_SIDEBAR_NEXT:
2325 case OP_SIDEBAR_PREV:
2326 case OP_SIDEBAR_NEXT_NEW:
2327 case OP_SIDEBAR_PREV_NEW:
2328 sidebar_scroll (op, menu->menu);
2331 if (menu->menu == MENU_MAIN)
2332 km_error_key (MENU_MAIN);
2335 if (menu->menu == MENU_PAGER) {
2336 menu->menu = MENU_MAIN;
2337 menu->redraw = REDRAW_FULL;
2339 set_option (OPTWEED); /* turn header weeding back on. */
2348 /* Close all open IMAP connections */
2351 /* Close all open NNTP connections */
2359 mutt_menuDestroy (&menu);
2363 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2370 for (color = ColorIndexList; color; color = color->next)
2371 if (mutt_pattern_exec
2372 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2373 curhdr->pair = color->pair;
2376 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];