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.
25 #include <lib-lib/mem.h>
26 #include <lib-lib/str.h>
27 #include <lib-lib/macros.h>
28 #include <lib-lib/mapping.h>
30 #include <lib-ui/sidebar.h>
41 #include "recvattach.h"
47 #include <imap/imap_private.h>
49 #include <lib-crypt/crypt.h>
52 #include "nntp/nntp.h"
56 #include "mutt_sasl.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);
609 continue; /* either user abort or timeout */
613 /* special handling for the tag-prefix function */
614 if (op == OP_TAG_PREFIX) {
616 mutt_error (_("No mailbox is open."));
621 if (!Context->tagged) {
622 mutt_error (_("No tagged messages."));
628 /* give visual indication that the next command is a tag- command */
629 mvaddstr (LINES - 1, 0, "tag-");
632 /* get the real command */
633 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
634 /* abort tag sequence */
635 CLEARLINE (LINES - 1);
639 else if (option (OPTAUTOTAG) && Context && Context->tagged)
642 if (op == OP_TAG_PREFIX_COND) {
644 mutt_error (_("No mailbox is open."));
649 if (!Context->tagged) {
652 while (UngetCount > 0) {
654 if (tmp.op == OP_END_COND)
657 mutt_message (_("Nothing to do."));
663 /* give visual indication that the next command is a tag- command */
664 mvaddstr (LINES - 1, 0, "tag-");
667 /* get the real command */
668 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
669 /* abort tag sequence */
670 CLEARLINE (LINES - 1);
678 if (menu->current < menu->max)
679 menu->oldcurrent = menu->current;
681 menu->oldcurrent = -1;
683 mutt_curs_set (1); /* fallback from the pager */
687 unset_option (OPTNEWS); /* for any case */
692 /* ----------------------------------------------------------------------
697 menu_bottom_page (menu);
700 menu_first_entry (menu);
703 menu_middle_page (menu);
709 menu_half_down (menu);
712 menu_next_line (menu);
715 menu_prev_line (menu);
718 menu_next_page (menu);
721 menu_prev_page (menu);
724 menu_last_entry (menu);
727 menu_top_page (menu);
730 menu_current_top (menu);
732 case OP_CURRENT_MIDDLE:
733 menu_current_middle (menu);
735 case OP_CURRENT_BOTTOM:
736 menu_current_bottom (menu);
743 if (Context->magic == M_NNTP) {
746 if (op == OP_GET_MESSAGE) {
748 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
753 string_list_t *ref = CURHDR->env->references;
756 mutt_error (_("Article has no parent reference!"));
760 m_strcpy(buf, sizeof(buf), ref->data);
762 if (!Context->id_hash)
763 Context->id_hash = mutt_make_id_hash (Context);
764 if ((h = hash_find (Context->id_hash, buf))) {
765 if (h->virtual != -1) {
766 menu->current = h->virtual;
767 menu->redraw = REDRAW_MOTION_RESYNCH;
769 else if (h->collapsed) {
770 mutt_uncollapse_thread (Context, h);
771 mutt_set_virtual (Context);
772 menu->current = h->virtual;
773 menu->redraw = REDRAW_MOTION_RESYNCH;
776 mutt_error (_("Message not visible in limited view."));
779 if (nntp_check_msgid (Context, buf) == 0) {
780 h = Context->hdrs[Context->msgcount - 1];
781 mutt_sort_headers (Context, 0);
782 menu->current = h->virtual;
783 menu->redraw = REDRAW_FULL;
786 mutt_error (_("Article %s not found on server"), buf);
791 case OP_GET_CHILDREN:
792 case OP_RECONSTRUCT_THREAD:
794 if (Context->magic == M_NNTP) {
796 int old = CURHDR->index;
798 if (!CURHDR->env->message_id) {
799 mutt_error (_("No Message-ID. Unable to perform operation"));
804 if (!Context->id_hash)
805 Context->id_hash = mutt_make_id_hash (Context);
806 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
808 if (op == OP_RECONSTRUCT_THREAD) {
809 string_list_t *ref = CURHDR->env->references;
812 nntp_check_msgid (Context, ref->data);
813 /* the last msgid in References is the root message */
815 m_strcpy(buf, sizeof(buf), ref->data);
819 mutt_message (_("Check for children of message..."));
821 if (nntp_check_children (Context, buf) == 0) {
822 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
823 h = hash_find (Context->id_hash, buf);
824 /* if the root message was retrieved, move to it */
826 menu->current = h->virtual;
827 else /* try to restore old position */
828 for (i = 0; i < Context->msgcount; i++)
829 if (Context->hdrs[i]->index == old) {
830 menu->current = Context->hdrs[i]->virtual;
831 /* As an added courtesy, recenter the menu
832 * with the current entry at the middle of the screen */
833 menu_check_recenter (menu);
834 menu_current_middle (menu);
837 menu->redraw = REDRAW_FULL;
847 if (isdigit (LastKey))
848 mutt_ungetch (LastKey, 0);
850 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
854 if (!isdigit ((unsigned char) buf[0])) {
855 mutt_error (_("Argument must be a message number."));
861 if (i > 0 && i <= Context->msgcount) {
862 for (j = i - 1; j < Context->msgcount; j++) {
863 if (Context->hdrs[j]->virtual != -1)
866 if (j >= Context->msgcount) {
867 for (j = i - 2; j >= 0; j--) {
868 if (Context->hdrs[j]->virtual != -1)
874 menu->current = Context->hdrs[j]->virtual;
875 if (menu->menu == MENU_PAGER) {
876 op = OP_DISPLAY_MESSAGE;
880 menu->redraw = REDRAW_MOTION;
883 mutt_error (_("That message is not visible."));
886 mutt_error (_("Invalid message number."));
890 /* --------------------------------------------------------------------
891 * `index' specific commands
894 case OP_MAIN_DELETE_PATTERN:
900 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
903 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
904 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
907 case OP_MAIN_FETCH_MAIL:
911 menu->redraw = REDRAW_FULL;
916 mutt_help (MENU_MAIN);
917 menu->redraw = REDRAW_FULL;
920 case OP_MAIN_SHOW_LIMIT:
922 if (!Context->pattern)
923 mutt_message (_("No limit pattern is in effect."));
928 /* i18n: ask for a limit to apply */
929 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
930 mutt_message ("%s", buffer);
938 menu->oldcurrent = (Context->vcount && menu->current >= 0
940 Context->vcount) ? CURHDR->index : -1;
941 if (op == OP_TOGGLE_READ) {
942 char buffer[LONG_STRING];
944 if (!Context->pattern
945 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
946 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
947 Context->pattern ? Context->pattern : ".*");
948 set_option (OPTHIDEREAD);
951 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
952 if (!*buf || strncmp (buf, ".*", 2) == 0)
953 snprintf (buf, sizeof (buf), "~A");
954 unset_option (OPTHIDEREAD);
956 p_delete(&Context->pattern);
957 Context->pattern = m_strdup(buf);
959 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
960 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
962 if (menu->oldcurrent >= 0) {
963 /* try to find what used to be the current message */
965 for (i = 0; i < Context->vcount; i++)
966 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
970 if (menu->current < 0)
975 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
976 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
977 mutt_draw_tree (Context);
978 menu->redraw = REDRAW_FULL;
980 if (Context->pattern)
981 mutt_message _("To view all messages, limit to \"all\".");
992 if (query_quadoption (OPT_QUIT, _("Quit Madmutt?")) == M_YES) {
995 oldcount = Context ? Context->msgcount : 0;
998 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1001 if (check == M_NEW_MAIL || check == M_REOPENED)
1002 update_index (menu, Context, check, oldcount, index_hint);
1004 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1005 set_option (OPTSEARCHINVALID);
1012 clearok (stdscr, TRUE);
1013 menu->redraw = REDRAW_FULL;
1017 case OP_SEARCH_REVERSE:
1018 case OP_SEARCH_NEXT:
1019 case OP_SEARCH_OPPOSITE:
1023 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1024 menu->current = menu->oldcurrent;
1026 menu->redraw = REDRAW_MOTION;
1030 case OP_SORT_REVERSE:
1032 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1033 if (Context && Context->msgcount) {
1034 resort_index (menu);
1035 set_option (OPTSEARCHINVALID);
1044 if (tag && !option (OPTAUTOTAG)) {
1045 for (j = 0; j < Context->vcount; j++)
1046 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1047 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1050 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1051 Context->last_tag = CURHDR->tagged ? CURHDR :
1052 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1053 ? NULL : Context->last_tag);
1054 menu->redraw = REDRAW_STATUS;
1055 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1057 menu->redraw |= REDRAW_MOTION_RESYNCH;
1060 menu->redraw |= REDRAW_CURRENT;
1064 case OP_MAIN_TAG_PATTERN:
1068 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1069 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1072 case OP_MAIN_UNDELETE_PATTERN:
1078 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1080 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1082 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1085 case OP_MAIN_UNTAG_PATTERN:
1089 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1090 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1093 /* --------------------------------------------------------------------
1094 * The following operations can be performed inside of the pager.
1097 case OP_MAIN_IMAP_FETCH:
1098 if (Context->magic == M_IMAP)
1099 imap_check_mailbox (Context, &index_hint, 1);
1102 case OP_MAIN_SYNC_FOLDER:
1104 if (Context && !Context->msgcount)
1111 int oldvcount = Context->vcount;
1112 oldcount = Context->msgcount;
1116 /* calculate the number of messages _above_ the cursor,
1117 * so we can keep the cursor on the current message
1119 for (j = 0; j <= menu->current; j++) {
1120 if (Context->hdrs[Context->v2r[j]]->deleted)
1124 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1125 if (Context->vcount != oldvcount)
1126 menu->current -= dcount;
1127 set_option (OPTSEARCHINVALID);
1129 else if (check == M_NEW_MAIL || check == M_REOPENED)
1130 update_index (menu, Context, check, oldcount, index_hint);
1133 * do a sanity check even if mx_sync_mailbox failed.
1136 if (menu->current < 0 || menu->current >= Context->vcount)
1137 menu->current = ci_first_message ();
1140 /* check for a fatal error, or all messages deleted */
1144 /* if we were in the pager, redisplay the message */
1145 if (menu->menu == MENU_PAGER) {
1146 op = OP_DISPLAY_MESSAGE;
1150 menu->redraw = REDRAW_FULL;
1153 case OP_SIDEBAR_OPEN:
1154 case OP_MAIN_CHANGE_FOLDER:
1155 case OP_MAIN_CHANGE_FOLDER_READONLY:
1157 case OP_MAIN_CHANGE_GROUP:
1158 case OP_MAIN_CHANGE_GROUP_READONLY:
1160 if (attach_msg || option (OPTREADONLY) ||
1162 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1164 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1170 cp = _("Open mailbox in read-only mode");
1172 cp = _("Open mailbox");
1176 unset_option (OPTNEWS);
1177 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1178 set_option (OPTNEWS);
1179 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1182 cp = _("Open newsgroup in read-only mode");
1184 cp = _("Open newsgroup");
1185 nntp_buffy (buf, sizeof (buf));
1190 if (Context && Context->path)
1191 m_strcpy(buf, sizeof(buf), Context->path);
1192 if (op != OP_SIDEBAR_OPEN)
1193 buffy_next (buf, sizeof (buf));
1196 if (op == OP_SIDEBAR_OPEN) {
1197 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1199 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1200 if (menu->menu == MENU_PAGER) {
1201 op = OP_DISPLAY_MESSAGE;
1207 CLEARLINE (LINES - 1);
1212 if (option (OPTNEWS)) {
1213 unset_option (OPTNEWS);
1214 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1218 mutt_expand_path (buf, sizeof (buf));
1219 if (mx_get_magic (buf) <= 0) {
1220 mutt_error (_("%s is not a mailbox."), buf);
1223 m_strreplace(&CurrentFolder, buf);
1228 if (Context->compressinfo && Context->realpath)
1229 m_strreplace(&LastFolder, Context->realpath);
1231 m_strreplace(&LastFolder, Context->path);
1232 oldcount = Context ? Context->msgcount : 0;
1234 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1235 if (check == M_NEW_MAIL || check == M_REOPENED)
1236 update_index (menu, Context, check, oldcount, index_hint);
1238 set_option (OPTSEARCHINVALID);
1239 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1247 /* Set CurrentMenu to MENU_MAIN before executing any folder
1248 * hooks so that all the index menu functions are available to
1252 CurrentMenu = MENU_MAIN;
1253 mutt_folder_hook (buf);
1255 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1256 menu->current = ci_first_message ();
1260 sidebar_set_current (buf);
1263 /* buffy_check() must be done with mail-reader mode! */
1264 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1266 && (Context->magic ==
1267 M_NNTP)) ? IndexNewsHelp :
1270 mutt_clear_error ();
1271 buffy_check (0); /* force the buffy check after we have changed
1273 menu->redraw = REDRAW_FULL;
1274 set_option (OPTSEARCHINVALID);
1277 case OP_DISPLAY_MESSAGE:
1278 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1283 * toggle the weeding of headers so that a user can press the key
1284 * again while reading the message.
1286 if (op == OP_DISPLAY_HEADERS)
1287 toggle_option (OPTWEED);
1289 unset_option (OPTNEEDRESORT);
1291 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1292 mutt_uncollapse_thread (Context, CURHDR);
1293 mutt_set_virtual (Context);
1294 if (option (OPTUNCOLLAPSEJUMP))
1295 menu->current = mutt_thread_next_unread (Context, CURHDR);
1298 if (option (OPTPGPAUTODEC) &&
1299 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1300 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1302 if ((op = mutt_display_message (CURHDR)) == -1) {
1303 unset_option (OPTNEEDRESORT);
1307 menu->menu = MENU_PAGER;
1308 menu->oldcurrent = menu->current;
1314 if (menu->menu == MENU_MAIN && attach_msg) {
1319 if ((menu->menu == MENU_MAIN)
1320 && (query_quadoption (OPT_QUIT,
1321 _("Exit Madmutt without saving?")) == M_YES))
1324 mx_fastclose_mailbox (Context);
1336 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1337 /* if we were in the pager, redisplay the message */
1338 if (menu->menu == MENU_PAGER) {
1339 op = OP_DISPLAY_MESSAGE;
1343 menu->redraw = REDRAW_CURRENT;
1346 case OP_MAIN_BREAK_THREAD:
1352 if ((Sort & SORT_MASK) != SORT_THREADS)
1353 mutt_error (_("Threading is not enabled."));
1357 HEADER *oldcur = CURHDR;
1359 mutt_break_thread (CURHDR);
1360 mutt_sort_headers (Context, 1);
1361 menu->current = oldcur->virtual;
1364 Context->changed = 1;
1365 mutt_message _("Thread broken");
1367 if (menu->menu == MENU_PAGER) {
1368 op = OP_DISPLAY_MESSAGE;
1372 menu->redraw |= REDRAW_INDEX;
1376 case OP_MAIN_LINK_THREADS:
1382 if ((Sort & SORT_MASK) != SORT_THREADS)
1383 mutt_error (_("Threading is not enabled."));
1385 else if (!CURHDR->env->message_id)
1386 mutt_error (_("No Message-ID: header available to link thread"));
1388 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1389 mutt_error (_("First, please tag a message to be linked here"));
1392 HEADER *oldcur = CURHDR;
1394 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1396 mutt_sort_headers (Context, 1);
1397 menu->current = oldcur->virtual;
1399 Context->changed = 1;
1400 mutt_message _("Threads linked");
1403 mutt_error (_("No thread linked"));
1406 if (menu->menu == MENU_PAGER) {
1407 op = OP_DISPLAY_MESSAGE;
1411 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1414 case OP_MAIN_NEXT_UNDELETED:
1418 if (menu->current >= Context->vcount - 1) {
1419 if (menu->menu == MENU_MAIN)
1420 mutt_error (_("You are on the last message."));
1424 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1425 menu->current = menu->oldcurrent;
1426 if (menu->menu == MENU_MAIN)
1427 mutt_error (_("No undeleted messages."));
1429 else if (menu->menu == MENU_PAGER) {
1430 op = OP_DISPLAY_MESSAGE;
1434 menu->redraw = REDRAW_MOTION;
1441 if (menu->current >= Context->vcount - 1) {
1442 if (menu->menu == MENU_MAIN)
1443 mutt_error (_("You are on the last message."));
1448 if (menu->menu == MENU_PAGER) {
1449 op = OP_DISPLAY_MESSAGE;
1453 menu->redraw = REDRAW_MOTION;
1456 case OP_MAIN_PREV_UNDELETED:
1460 if (menu->current < 1) {
1461 mutt_error (_("You are on the first message."));
1465 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1466 menu->current = menu->oldcurrent;
1467 if (menu->menu == MENU_MAIN)
1468 mutt_error (_("No undeleted messages."));
1470 else if (menu->menu == MENU_PAGER) {
1471 op = OP_DISPLAY_MESSAGE;
1475 menu->redraw = REDRAW_MOTION;
1482 if (menu->current < 1) {
1483 if (menu->menu == MENU_MAIN)
1484 mutt_error (_("You are on the first message."));
1489 if (menu->menu == MENU_PAGER) {
1490 op = OP_DISPLAY_MESSAGE;
1494 menu->redraw = REDRAW_MOTION;
1497 case OP_DECRYPT_COPY:
1498 case OP_DECRYPT_SAVE:
1499 case OP_COPY_MESSAGE:
1501 case OP_DECODE_COPY:
1502 case OP_DECODE_SAVE:
1505 if (mutt_save_message (tag ? NULL : CURHDR,
1506 (op == OP_DECRYPT_SAVE) ||
1507 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1508 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1509 (op == OP_DECRYPT_SAVE)
1510 || (op == OP_DECRYPT_COPY)
1511 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1518 menu->redraw |= REDRAW_INDEX;
1519 else if (option (OPTRESOLVE)) {
1520 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1521 menu->current = menu->oldcurrent;
1522 menu->redraw |= REDRAW_CURRENT;
1525 menu->redraw |= REDRAW_MOTION_RESYNCH;
1528 menu->redraw |= REDRAW_CURRENT;
1532 case OP_MAIN_NEXT_NEW:
1533 case OP_MAIN_NEXT_UNREAD:
1534 case OP_MAIN_PREV_NEW:
1535 case OP_MAIN_PREV_UNREAD:
1536 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1537 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1540 int first_unread = -1;
1548 for (j = 0; j != Context->vcount; j++) {
1549 #define CURHDRi Context->hdrs[Context->v2r[i]]
1550 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1551 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1553 if (i > Context->vcount - 1) {
1554 mutt_message _("Search wrapped to top.");
1562 mutt_message _("Search wrapped to bottom.");
1564 i = Context->vcount - 1;
1568 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1569 if (UNREAD (CURHDRi) && first_unread == -1)
1571 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1574 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1575 if (first_unread == -1)
1577 if ((!CURHDRi->old) && first_new == -1)
1581 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1584 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1585 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1586 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1591 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1592 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1593 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1595 menu->current = first_new;
1596 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1597 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1598 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1599 && first_unread != -1)
1600 menu->current = first_unread;
1602 if (menu->current == -1) {
1603 menu->current = menu->oldcurrent;
1604 mutt_error ("%s%s.",
1605 (op == OP_MAIN_NEXT_NEW
1607 OP_MAIN_PREV_NEW) ? _("No new messages") :
1608 _("No unread messages"),
1609 Context->pattern ? _(" in this limited view") : "");
1611 else if (menu->menu == MENU_PAGER) {
1612 op = OP_DISPLAY_MESSAGE;
1616 menu->redraw = REDRAW_MOTION;
1619 case OP_FLAG_MESSAGE:
1625 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1628 for (j = 0; j < Context->vcount; j++) {
1629 if (Context->hdrs[Context->v2r[j]]->tagged)
1630 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1631 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1634 menu->redraw |= REDRAW_INDEX;
1637 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1638 if (option (OPTRESOLVE)) {
1639 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1640 menu->current = menu->oldcurrent;
1641 menu->redraw = REDRAW_CURRENT;
1644 menu->redraw = REDRAW_MOTION_RESYNCH;
1647 menu->redraw = REDRAW_CURRENT;
1649 menu->redraw |= REDRAW_STATUS;
1658 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1661 for (j = 0; j < Context->vcount; j++) {
1662 if (Context->hdrs[Context->v2r[j]]->tagged) {
1663 if (Context->hdrs[Context->v2r[j]]->read ||
1664 Context->hdrs[Context->v2r[j]]->old)
1665 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1668 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1672 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1675 if (CURHDR->read || CURHDR->old)
1676 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1678 mutt_set_flag (Context, CURHDR, M_READ, 1);
1680 if (option (OPTRESOLVE)) {
1681 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1682 menu->current = menu->oldcurrent;
1683 menu->redraw = REDRAW_CURRENT;
1686 menu->redraw = REDRAW_MOTION_RESYNCH;
1689 menu->redraw = REDRAW_CURRENT;
1690 menu->redraw |= REDRAW_STATUS;
1694 case OP_TOGGLE_WRITE:
1697 if (mx_toggle_write (Context) == 0)
1698 menu->redraw |= REDRAW_STATUS;
1701 case OP_MAIN_NEXT_THREAD:
1702 case OP_MAIN_NEXT_SUBTHREAD:
1703 case OP_MAIN_PREV_THREAD:
1704 case OP_MAIN_PREV_SUBTHREAD:
1709 case OP_MAIN_NEXT_THREAD:
1710 menu->current = mutt_next_thread (CURHDR);
1713 case OP_MAIN_NEXT_SUBTHREAD:
1714 menu->current = mutt_next_subthread (CURHDR);
1717 case OP_MAIN_PREV_THREAD:
1718 menu->current = mutt_previous_thread (CURHDR);
1721 case OP_MAIN_PREV_SUBTHREAD:
1722 menu->current = mutt_previous_subthread (CURHDR);
1726 if (menu->current < 0) {
1727 menu->current = menu->oldcurrent;
1728 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1729 mutt_error (_("No more threads."));
1732 mutt_error (_("You are on the first thread."));
1734 else if (menu->menu == MENU_PAGER) {
1735 op = OP_DISPLAY_MESSAGE;
1739 menu->redraw = REDRAW_MOTION;
1742 case OP_MAIN_PARENT_MESSAGE:
1747 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1748 menu->current = menu->oldcurrent;
1750 else if (menu->menu == MENU_PAGER) {
1751 op = OP_DISPLAY_MESSAGE;
1755 menu->redraw = REDRAW_MOTION;
1758 case OP_MAIN_SET_FLAG:
1759 case OP_MAIN_CLEAR_FLAG:
1765 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1767 menu->redraw = REDRAW_STATUS;
1769 menu->redraw |= REDRAW_INDEX;
1770 else if (option (OPTRESOLVE)) {
1771 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1772 menu->current = menu->oldcurrent;
1773 menu->redraw |= REDRAW_CURRENT;
1776 menu->redraw |= REDRAW_MOTION_RESYNCH;
1779 menu->redraw |= REDRAW_CURRENT;
1783 case OP_MAIN_COLLAPSE_THREAD:
1787 if ((Sort & SORT_MASK) != SORT_THREADS) {
1788 mutt_error (_("Threading is not enabled."));
1793 if (CURHDR->collapsed) {
1794 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1795 mutt_set_virtual (Context);
1796 if (option (OPTUNCOLLAPSEJUMP))
1797 menu->current = mutt_thread_next_unread (Context, CURHDR);
1799 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1800 menu->current = mutt_collapse_thread (Context, CURHDR);
1801 mutt_set_virtual (Context);
1804 mutt_error (_("Thread contains unread messages."));
1809 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1813 case OP_MAIN_COLLAPSE_ALL:
1817 if ((Sort & SORT_MASK) != SORT_THREADS) {
1818 mutt_error (_("Threading is not enabled."));
1825 THREAD *thread, *top;
1828 if (CURHDR->collapsed)
1829 final = mutt_uncollapse_thread (Context, CURHDR);
1830 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1831 final = mutt_collapse_thread (Context, CURHDR);
1833 final = CURHDR->virtual;
1835 base = Context->hdrs[Context->v2r[final]];
1837 top = Context->tree;
1838 Context->collapsed = !Context->collapsed;
1839 while ((thread = top) != NULL) {
1840 while (!thread->message)
1841 thread = thread->child;
1842 h = thread->message;
1844 if (h->collapsed != Context->collapsed) {
1846 mutt_uncollapse_thread (Context, h);
1847 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1848 mutt_collapse_thread (Context, h);
1853 mutt_set_virtual (Context);
1854 for (j = 0; j < Context->vcount; j++) {
1855 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1861 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1865 /* --------------------------------------------------------------------
1866 * These functions are invoked directly from the internal-pager
1869 case OP_BOUNCE_MESSAGE:
1874 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1877 case OP_CREATE_ALIAS:
1879 mutt_create_alias (Context
1880 && Context->vcount ? CURHDR->env : NULL, NULL);
1881 MAYBE_REDRAW (menu->redraw);
1882 menu->redraw |= REDRAW_CURRENT;
1887 mutt_query_menu (NULL, 0);
1888 MAYBE_REDRAW (menu->redraw);
1891 case OP_PURGE_MESSAGE:
1898 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1901 mutt_tag_set_flag (M_DELETE, 1);
1902 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1903 if (option (OPTDELETEUNTAG))
1904 mutt_tag_set_flag (M_TAG, 0);
1905 menu->redraw = REDRAW_INDEX;
1908 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1909 mutt_set_flag (Context, CURHDR, M_PURGED,
1910 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1911 if (option (OPTDELETEUNTAG))
1912 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1913 if (option (OPTRESOLVE)) {
1914 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1915 menu->current = menu->oldcurrent;
1916 menu->redraw = REDRAW_CURRENT;
1918 else if (menu->menu == MENU_PAGER) {
1919 op = OP_DISPLAY_MESSAGE;
1923 menu->redraw |= REDRAW_MOTION_RESYNCH;
1926 menu->redraw = REDRAW_CURRENT;
1928 menu->redraw |= REDRAW_STATUS;
1931 case OP_DELETE_THREAD:
1932 case OP_DELETE_SUBTHREAD:
1938 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1940 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1941 op == OP_DELETE_THREAD ? 0 : 1);
1944 if (option (OPTDELETEUNTAG))
1945 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1946 op == OP_DELETE_THREAD ? 0 : 1);
1947 if (option (OPTRESOLVE))
1948 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1949 menu->current = menu->oldcurrent;
1950 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1956 if (Context && Context->magic == M_NNTP) {
1957 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1958 ((NNTP_DATA *) Context->data)->group))
1959 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1964 case OP_DISPLAY_ADDRESS:
1968 mutt_display_address (CURHDR->env);
1971 case OP_ENTER_COMMAND:
1973 CurrentMenu = MENU_MAIN;
1974 mutt_enter_command ();
1975 mutt_check_rescore (Context);
1976 if (option (OPTFORCEREDRAWINDEX))
1977 menu->redraw = REDRAW_FULL;
1978 unset_option (OPTFORCEREDRAWINDEX);
1979 unset_option (OPTFORCEREDRAWPAGER);
1982 case OP_EDIT_MESSAGE:
1989 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1991 if (option (OPTPGPAUTODEC)
1992 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1993 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1994 mutt_edit_message (Context, tag ? NULL : CURHDR);
1995 menu->redraw = REDRAW_FULL;
1999 case OP_FORWARD_MESSAGE:
2005 if (option (OPTPGPAUTODEC) &&
2006 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2007 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2008 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2009 menu->redraw = REDRAW_FULL;
2013 case OP_FORGET_PASSPHRASE:
2014 crypt_forget_passphrase ();
2017 case OP_GROUP_REPLY:
2023 if (option (OPTPGPAUTODEC) &&
2024 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2025 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2027 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2028 tag ? NULL : CURHDR);
2029 menu->redraw = REDRAW_FULL;
2038 if (option (OPTPGPAUTODEC) &&
2039 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2040 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2042 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2043 tag ? NULL : CURHDR);
2044 menu->redraw = REDRAW_FULL;
2050 ci_send_message (0, NULL, NULL, Context, NULL);
2051 menu->redraw = REDRAW_FULL;
2056 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2057 menu->redraw = REDRAW_FULL;
2061 case OP_EXTRACT_KEYS:
2064 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2065 menu->redraw = REDRAW_FULL;
2069 case OP_CHECK_TRADITIONAL:
2072 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2073 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2075 if (menu->menu == MENU_PAGER) {
2076 op = OP_DISPLAY_MESSAGE;
2085 mutt_pipe_message (tag ? NULL : CURHDR);
2086 /* in an IMAP folder index with imap_peek=no, piping could change
2087 * * new or old messages status to read. Redraw what's needed.
2089 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2090 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2092 MAYBE_REDRAW (menu->redraw);
2099 mutt_print_message (tag ? NULL : CURHDR);
2100 /* in an IMAP folder index with imap_peek=no, piping could change
2101 * * new or old messages status to read. Redraw what's needed.
2103 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2104 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2108 case OP_MAIN_READ_THREAD:
2109 case OP_MAIN_READ_SUBTHREAD:
2115 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2117 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2118 op == OP_MAIN_READ_THREAD ? 0 : 1);
2121 if (option (OPTRESOLVE)) {
2122 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2123 mutt_next_thread (CURHDR) :
2124 mutt_next_subthread (CURHDR))) == -1)
2125 menu->current = menu->oldcurrent;
2127 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2131 case OP_RECALL_MESSAGE:
2134 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2135 menu->redraw = REDRAW_FULL;
2145 for (j = 0; j < Context->vcount; j++) {
2146 if (Context->hdrs[Context->v2r[j]]->tagged)
2147 mutt_resend_message (NULL, Context,
2148 Context->hdrs[Context->v2r[j]]);
2152 mutt_resend_message (NULL, Context, CURHDR);
2154 menu->redraw = REDRAW_FULL;
2160 case OP_FORWARD_TO_GROUP:
2163 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2164 Context && Context->msgcount == 0) {
2165 mutt_error (_("There are no messages."));
2168 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2169 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2170 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2171 _("Reply by mail as poster prefers?")) !=
2173 if (Context && Context->magic == M_NNTP
2174 && !((NNTP_DATA *) Context->data)->allowed
2175 && query_quadoption (OPT_TOMODERATED,
2177 ("Posting to this group not allowed, may be moderated. Continue?"))
2181 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2184 if (op == OP_FOLLOWUP)
2185 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2186 tag ? NULL : CURHDR);
2188 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2189 tag ? NULL : CURHDR);
2191 menu->redraw = REDRAW_FULL;
2202 if (option (OPTPGPAUTODEC) &&
2203 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2204 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2206 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2207 menu->redraw = REDRAW_FULL;
2210 case OP_SHELL_ESCAPE:
2212 mutt_shell_escape ();
2213 MAYBE_REDRAW (menu->redraw);
2217 case OP_TAG_SUBTHREAD:
2221 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2222 op == OP_TAG_THREAD ? 0 : 1);
2225 if (option (OPTRESOLVE)) {
2226 menu->current = mutt_next_thread (CURHDR);
2228 if (menu->current == -1)
2229 menu->current = menu->oldcurrent;
2231 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2241 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2244 mutt_tag_set_flag (M_DELETE, 0);
2245 mutt_tag_set_flag (M_PURGED, 0);
2246 menu->redraw = REDRAW_INDEX;
2249 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2250 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2251 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2253 menu->redraw = REDRAW_MOTION_RESYNCH;
2256 menu->redraw = REDRAW_CURRENT;
2258 menu->redraw |= REDRAW_STATUS;
2261 case OP_UNDELETE_THREAD:
2262 case OP_UNDELETE_SUBTHREAD:
2268 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2270 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2271 op == OP_UNDELETE_THREAD ? 0 : 1)
2272 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2273 op == OP_UNDELETE_THREAD ? 0 : 1);
2276 if (option (OPTRESOLVE)) {
2277 if (op == OP_UNDELETE_THREAD)
2278 menu->current = mutt_next_thread (CURHDR);
2280 menu->current = mutt_next_subthread (CURHDR);
2282 if (menu->current == -1)
2283 menu->current = menu->oldcurrent;
2285 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2294 if (option (OPTFORCEBUFFYCHECK))
2297 menu->redraw = REDRAW_FULL;
2300 case OP_VIEW_ATTACHMENTS:
2303 mutt_view_attachments (CURHDR);
2304 if (CURHDR->attach_del)
2305 Context->changed = 1;
2306 menu->redraw = REDRAW_FULL;
2316 case OP_REBUILD_CACHE:
2317 mx_rebuild_cache ();
2320 case OP_SIDEBAR_SCROLL_UP:
2321 case OP_SIDEBAR_SCROLL_DOWN:
2322 case OP_SIDEBAR_NEXT:
2323 case OP_SIDEBAR_PREV:
2324 case OP_SIDEBAR_NEXT_NEW:
2325 case OP_SIDEBAR_PREV_NEW:
2326 sidebar_scroll (op, menu->menu);
2329 if (menu->menu == MENU_MAIN)
2330 km_error_key (MENU_MAIN);
2333 if (menu->menu == MENU_PAGER) {
2334 menu->menu = MENU_MAIN;
2335 menu->redraw = REDRAW_FULL;
2337 set_option (OPTWEED); /* turn header weeding back on. */
2346 /* Close all open IMAP connections */
2349 /* Close all open NNTP connections */
2357 mutt_menuDestroy (&menu);
2361 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2368 for (color = ColorIndexList; color; color = color->next)
2369 if (mutt_pattern_exec
2370 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2371 curhdr->pair = color->pair;
2374 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];