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/lib-lib.h>
27 #include <lib-ui/sidebar.h>
38 #include "recvattach.h"
44 #include <imap/imap_private.h>
46 #include <lib-crypt/crypt.h>
49 #include "nntp/nntp.h"
53 #include "mutt_sasl.h"
56 static const char *No_mailbox_is_open = N_("No mailbox is open.");
57 static const char *There_are_no_messages = N_("There are no messages.");
58 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
59 static const char *Function_not_permitted_in_attach_message_mode =
60 N_("Function not permitted in attach-message mode.");
61 static const char *No_visible = N_("No visible messages.");
63 #define CHECK_IN_MAILBOX if (!Context) \
66 mutt_error (_(No_mailbox_is_open)); \
70 #define CHECK_MSGCOUNT if (!Context) \
73 mutt_error(_(No_mailbox_is_open)); \
76 else if (!Context->msgcount) \
79 mutt_error(_(There_are_no_messages)); \
83 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
86 mutt_error(_(No_visible)); \
91 #define CHECK_READONLY if (Context->readonly) \
94 mutt_error(_(Mailbox_is_read_only)); \
98 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
101 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
105 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
106 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
107 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
108 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
110 extern size_t UngetCount;
112 void index_make_entry (char *s, ssize_t l, struct menu_t * menu, int num)
115 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
116 int edgemsgno, reverse = Sort & SORT_REVERSE;
117 HEADER *h = Context->hdrs[Context->v2r[num]];
120 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
121 flag |= M_FORMAT_TREE; /* display the thread tree */
122 if (h->display_subject)
123 flag |= M_FORMAT_FORCESUBJ;
126 if (menu->top + menu->pagelen > menu->max)
127 edgemsgno = Context->v2r[menu->max - 1];
129 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
132 edgemsgno = Context->v2r[menu->top];
134 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
138 /* if no ancestor is visible on current screen, provisionally force
140 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
142 flag |= M_FORMAT_FORCESUBJ;
145 else if (tmp->message->virtual >= 0)
148 if (flag & M_FORMAT_FORCESUBJ) {
149 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
153 /* ...but if a previous sibling is available, don't force it */
154 if (reverse ? tmp->message->msgno >
155 edgemsgno : tmp->message->msgno < edgemsgno)
157 else if (tmp->message->virtual >= 0) {
158 flag &= ~M_FORMAT_FORCESUBJ;
166 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
169 int index_color (int index_no)
171 HEADER *h = Context->hdrs[Context->v2r[index_no]];
176 mutt_set_header_color (Context, h);
180 static int ci_next_undeleted (int msgno)
184 for (i = msgno + 1; i < Context->vcount; i++)
185 if (!Context->hdrs[Context->v2r[i]]->deleted)
190 static int ci_previous_undeleted (int msgno)
194 for (i = msgno - 1; i >= 0; i--)
195 if (!Context->hdrs[Context->v2r[i]]->deleted)
200 /* Return the index of the first new message, or failing that, the first
203 static int ci_first_message (void)
207 if (Context && Context->msgcount) {
208 for (i = 0; i < Context->vcount; i++) {
209 if (!Context->hdrs[Context->v2r[i]]->read &&
210 !Context->hdrs[Context->v2r[i]]->deleted) {
211 if (!Context->hdrs[Context->v2r[i]]->old)
220 /* If Sort is reverse and not threaded, the latest message is first.
221 * If Sort is threaded, the latest message is first iff exactly one
222 * of Sort and SortAux are reverse.
224 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
225 ((Sort & SORT_MASK) == SORT_THREADS &&
226 ((Sort ^ SortAux) & SORT_REVERSE)))
229 return (Context->vcount ? Context->vcount - 1 : 0);
234 /* This should be in mx.c, but it only gets used here. */
235 static int mx_toggle_write (CONTEXT * ctx)
241 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
246 if (ctx->dontwrite) {
248 mutt_message (_("Changes to folder will be written on folder exit."));
252 mutt_message (_("Changes to folder will not be written."));
258 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
259 int oldcount, int index_hint)
261 /* store pointers to the newly added messages */
262 HEADER **save_new = NULL;
265 /* take note of the current message */
267 if (menu->current < Context->vcount)
268 menu->oldcurrent = index_hint;
270 oldcount = 0; /* invalid message number! */
273 /* We are in a limited view. Check if the new message(s) satisfy
274 * the limit criteria. If they do, set their virtual msgno so that
275 * they will be visible in the limited view */
276 if (Context->pattern) {
277 #define THIS_BODY Context->hdrs[j]->content
278 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
279 if (mutt_pattern_exec
280 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
282 Context->hdrs[j]->virtual = Context->vcount;
283 Context->v2r[Context->vcount] = j;
284 Context->hdrs[j]->limited = 1;
287 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
293 /* save the list of new messages */
294 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
295 save_new = p_new(HEADER*, Context->msgcount - oldcount);
296 for (j = oldcount; j < Context->msgcount; j++)
297 save_new[j - oldcount] = Context->hdrs[j];
300 /* if the mailbox was reopened, need to rethread from scratch */
301 mutt_sort_headers (Context, (check == M_REOPENED));
303 /* uncollapse threads with new mail */
304 if ((Sort & SORT_MASK) == SORT_THREADS) {
305 if (check == M_REOPENED) {
308 Context->collapsed = 0;
310 for (h = Context->tree; h; h = h->next) {
311 for (c = h; !c->message; c = c->child);
312 mutt_uncollapse_thread (Context, c->message);
314 mutt_set_virtual (Context);
317 for (j = 0; j < Context->msgcount - oldcount; j++) {
320 for (k = 0; k < Context->msgcount; k++) {
321 HEADER *h = Context->hdrs[k];
323 if (h == save_new[j] && (!Context->pattern || h->limited))
324 mutt_uncollapse_thread (Context, h);
328 mutt_set_virtual (Context);
334 /* restore the current message to the message it was pointing to */
335 for (j = 0; j < Context->vcount; j++) {
336 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
343 if (menu->current < 0)
344 menu->current = ci_first_message ();
347 static void resort_index (MUTTMENU * menu)
350 HEADER *current = CURHDR;
353 mutt_sort_headers (Context, 0);
354 /* Restore the current message */
356 for (i = 0; i < Context->vcount; i++) {
357 if (Context->hdrs[Context->v2r[i]] == current) {
363 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
364 menu->current = mutt_parent_message (Context, current);
366 if (menu->current < 0)
367 menu->current = ci_first_message ();
369 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
372 struct mapping_t IndexHelp[] = {
373 {N_("Quit"), OP_QUIT},
374 {N_("Del"), OP_DELETE},
375 {N_("Undel"), OP_UNDELETE},
376 {N_("Save"), OP_SAVE},
377 {N_("Mail"), OP_MAIL},
378 {N_("Reply"), OP_REPLY},
379 {N_("Group"), OP_GROUP_REPLY},
380 {N_("Help"), OP_HELP},
385 struct mapping_t IndexNewsHelp[] = {
386 {N_("Quit"), OP_QUIT},
387 {N_("Del"), OP_DELETE},
388 {N_("Undel"), OP_UNDELETE},
389 {N_("Save"), OP_SAVE},
390 {N_("Post"), OP_POST},
391 {N_("Followup"), OP_FOLLOWUP},
392 {N_("Catchup"), OP_CATCHUP},
393 {N_("Help"), OP_HELP},
398 /* This function handles the message index window as well as commands returned
399 * from the pager (MENU_PAGER).
401 int mutt_index_menu (void)
403 char buf[LONG_STRING], helpstr[SHORT_STRING];
406 int done = 0; /* controls when to exit the "event" loop */
408 int tag = 0; /* has the tag-prefix command been pressed? */
413 char *cp; /* temporary variable. */
414 int index_hint; /* used to restore cursor position */
415 int do_buffy_notify = 1;
416 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
417 int attach_msg = option (OPTATTACHMSG);
419 menu = mutt_new_menu ();
420 menu->menu = MENU_MAIN;
422 menu->pagelen = LINES - 3;
423 menu->make_entry = (void *) index_make_entry;
424 menu->color = index_color;
425 menu->current = ci_first_message ();
426 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
429 && (Context->magic ==
430 M_NNTP)) ? IndexNewsHelp :
435 buffy_check (0); /* force the buffy check after we enter the folder */
436 /* record folder we open to place sidebar indicator properly */
437 if (Context && Context->path)
438 sidebar_set_current (Context->path);
442 tag = 0; /* clear the tag-prefix */
444 menu->max = Context ? Context->vcount : 0;
445 oldcount = Context ? Context->msgcount : 0;
447 /* check if we need to resort the index because just about
448 * any 'op' below could do mutt_enter_command(), either here or
449 * from any new menu launched, and change $sort/$sort_aux
451 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
454 if (option (OPTREDRAWTREE) && Context && Context->msgcount
455 && (Sort & SORT_MASK) == SORT_THREADS) {
456 mutt_draw_tree (Context);
457 menu->redraw |= REDRAW_STATUS;
458 unset_option (OPTREDRAWTREE);
461 if (Context && !attach_msg) {
464 /* check for new mail in the mailbox. If nonzero, then something has
465 * changed about the file (either we got new mail or the file was
466 * modified underneath us.)
469 imap_allow_reopen (Context);
471 index_hint = (Context->vcount && menu->current >= 0
472 && menu->current < Context->vcount) ? CURHDR->index : 0;
474 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
475 if (!Context->path) {
476 /* fatal error occurred */
478 menu->redraw = REDRAW_FULL;
480 set_option (OPTSEARCHINVALID);
482 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
483 update_index (menu, Context, check, oldcount, index_hint);
485 /* notify the user of new mail */
486 if (check == M_REOPENED)
488 ("Mailbox was externally modified. Flags may be wrong."));
489 else if (check == M_NEW_MAIL) {
490 /* on new mail: redraw sidebar */
491 sidebar_draw (CurrentMenu);
492 mutt_message (_("New mail in this mailbox."));
494 if (option (OPTBEEPNEW))
497 else if (check == M_FLAGS)
498 mutt_message (_("Mailbox was externally modified."));
500 /* avoid the message being overwritten by buffy */
503 menu->redraw = REDRAW_FULL;
504 menu->max = Context->vcount;
506 set_option (OPTSEARCHINVALID);
511 imap_disallow_reopen (Context);
514 /* check for new mail in the incoming folders */
516 if ((newcount = buffy_check (0)) != oldcount) {
517 menu->redraw |= REDRAW_STATUS;
518 menu->redraw |= REDRAW_SIDEBAR;
520 if (do_buffy_notify) {
521 if (buffy_notify () && option (OPTBEEPNEW))
530 if (menu->redraw & REDRAW_SIDEBAR)
531 sidebar_draw (menu->menu);
532 if (menu->redraw & REDRAW_FULL) {
533 menu_redraw_full (menu);
534 sidebar_draw (menu->menu);
538 if (menu->menu == MENU_MAIN) {
539 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
540 menu_check_recenter (menu);
542 if (menu->redraw & REDRAW_INDEX) {
543 menu_redraw_index (menu);
544 menu->redraw |= REDRAW_STATUS;
546 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
547 menu_redraw_motion (menu);
548 else if (menu->redraw & REDRAW_CURRENT)
549 menu_redraw_current (menu);
552 if (menu->redraw & REDRAW_STATUS) {
553 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
554 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
555 sidebar_draw_frames();
556 SETCOLOR (MT_COLOR_STATUS);
557 BKGDSET (MT_COLOR_STATUS);
558 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
559 mutt_paddstr (COLS-SW, buf);
560 SETCOLOR (MT_COLOR_NORMAL);
561 BKGDSET (MT_COLOR_NORMAL);
562 sidebar_set_buffystats (Context);
563 menu->redraw &= ~REDRAW_STATUS;
564 if (option (OPTXTERMSETTITLES)) {
565 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
566 mutt_xterm_set_title (buf);
567 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
568 mutt_xterm_set_icon (buf);
573 if (menu->current < menu->max)
574 menu->oldcurrent = menu->current;
576 menu->oldcurrent = -1;
578 if (option (OPTARROWCURSOR))
579 move (menu->current - menu->top + menu->offset, 2);
580 else if (option (OPTBRAILLEFRIENDLY))
581 move (menu->current - menu->top + menu->offset, 0);
583 move (menu->current - menu->top + menu->offset, COLS - 1);
586 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
589 mutt_resize_screen ();
590 menu->redraw = REDRAW_FULL;
591 menu->menu = MENU_MAIN;
593 menu->top = 0; /* so we scroll the right amount */
595 * force a real complete redraw. clrtobot() doesn't seem to be able
596 * to handle every case without this.
598 clearok (stdscr, TRUE);
603 op = km_dokey (MENU_MAIN);
606 continue; /* either user abort or timeout */
610 /* special handling for the tag-prefix function */
611 if (op == OP_TAG_PREFIX) {
613 mutt_error (_("No mailbox is open."));
618 if (!Context->tagged) {
619 mutt_error (_("No tagged messages."));
625 /* give visual indication that the next command is a tag- command */
626 mvaddstr (LINES - 1, 0, "tag-");
629 /* get the real command */
630 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
631 /* abort tag sequence */
632 CLEARLINE (LINES - 1);
636 else if (option (OPTAUTOTAG) && Context && Context->tagged)
639 if (op == OP_TAG_PREFIX_COND) {
641 mutt_error (_("No mailbox is open."));
646 if (!Context->tagged) {
649 while (UngetCount > 0) {
651 if (tmp.op == OP_END_COND)
654 mutt_message (_("Nothing to do."));
660 /* give visual indication that the next command is a tag- command */
661 mvaddstr (LINES - 1, 0, "tag-");
664 /* get the real command */
665 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
666 /* abort tag sequence */
667 CLEARLINE (LINES - 1);
675 if (menu->current < menu->max)
676 menu->oldcurrent = menu->current;
678 menu->oldcurrent = -1;
680 mutt_curs_set (1); /* fallback from the pager */
684 unset_option (OPTNEWS); /* for any case */
689 /* ----------------------------------------------------------------------
694 menu_bottom_page (menu);
697 menu_first_entry (menu);
700 menu_middle_page (menu);
706 menu_half_down (menu);
709 menu_next_line (menu);
712 menu_prev_line (menu);
715 menu_next_page (menu);
718 menu_prev_page (menu);
721 menu_last_entry (menu);
724 menu_top_page (menu);
727 menu_current_top (menu);
729 case OP_CURRENT_MIDDLE:
730 menu_current_middle (menu);
732 case OP_CURRENT_BOTTOM:
733 menu_current_bottom (menu);
740 if (Context->magic == M_NNTP) {
743 if (op == OP_GET_MESSAGE) {
745 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
750 string_list_t *ref = CURHDR->env->references;
753 mutt_error (_("Article has no parent reference!"));
757 m_strcpy(buf, sizeof(buf), ref->data);
759 if (!Context->id_hash)
760 Context->id_hash = mutt_make_id_hash (Context);
761 if ((h = hash_find (Context->id_hash, buf))) {
762 if (h->virtual != -1) {
763 menu->current = h->virtual;
764 menu->redraw = REDRAW_MOTION_RESYNCH;
766 else if (h->collapsed) {
767 mutt_uncollapse_thread (Context, h);
768 mutt_set_virtual (Context);
769 menu->current = h->virtual;
770 menu->redraw = REDRAW_MOTION_RESYNCH;
773 mutt_error (_("Message not visible in limited view."));
776 if (nntp_check_msgid (Context, buf) == 0) {
777 h = Context->hdrs[Context->msgcount - 1];
778 mutt_sort_headers (Context, 0);
779 menu->current = h->virtual;
780 menu->redraw = REDRAW_FULL;
783 mutt_error (_("Article %s not found on server"), buf);
788 case OP_GET_CHILDREN:
789 case OP_RECONSTRUCT_THREAD:
791 if (Context->magic == M_NNTP) {
793 int old = CURHDR->index;
795 if (!CURHDR->env->message_id) {
796 mutt_error (_("No Message-ID. Unable to perform operation"));
801 if (!Context->id_hash)
802 Context->id_hash = mutt_make_id_hash (Context);
803 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
805 if (op == OP_RECONSTRUCT_THREAD) {
806 string_list_t *ref = CURHDR->env->references;
809 nntp_check_msgid (Context, ref->data);
810 /* the last msgid in References is the root message */
812 m_strcpy(buf, sizeof(buf), ref->data);
816 mutt_message (_("Check for children of message..."));
818 if (nntp_check_children (Context, buf) == 0) {
819 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
820 h = hash_find (Context->id_hash, buf);
821 /* if the root message was retrieved, move to it */
823 menu->current = h->virtual;
824 else /* try to restore old position */
825 for (i = 0; i < Context->msgcount; i++)
826 if (Context->hdrs[i]->index == old) {
827 menu->current = Context->hdrs[i]->virtual;
828 /* As an added courtesy, recenter the menu
829 * with the current entry at the middle of the screen */
830 menu_check_recenter (menu);
831 menu_current_middle (menu);
834 menu->redraw = REDRAW_FULL;
844 if (isdigit (LastKey))
845 mutt_ungetch (LastKey, 0);
847 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
851 if (!isdigit ((unsigned char) buf[0])) {
852 mutt_error (_("Argument must be a message number."));
858 if (i > 0 && i <= Context->msgcount) {
859 for (j = i - 1; j < Context->msgcount; j++) {
860 if (Context->hdrs[j]->virtual != -1)
863 if (j >= Context->msgcount) {
864 for (j = i - 2; j >= 0; j--) {
865 if (Context->hdrs[j]->virtual != -1)
871 menu->current = Context->hdrs[j]->virtual;
872 if (menu->menu == MENU_PAGER) {
873 op = OP_DISPLAY_MESSAGE;
877 menu->redraw = REDRAW_MOTION;
880 mutt_error (_("That message is not visible."));
883 mutt_error (_("Invalid message number."));
887 /* --------------------------------------------------------------------
888 * `index' specific commands
891 case OP_MAIN_DELETE_PATTERN:
897 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
900 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
901 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
904 case OP_MAIN_FETCH_MAIL:
908 menu->redraw = REDRAW_FULL;
913 mutt_help (MENU_MAIN);
914 menu->redraw = REDRAW_FULL;
917 case OP_MAIN_SHOW_LIMIT:
919 if (!Context->pattern)
920 mutt_message (_("No limit pattern is in effect."));
925 /* i18n: ask for a limit to apply */
926 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
927 mutt_message ("%s", buffer);
935 menu->oldcurrent = (Context->vcount && menu->current >= 0
937 Context->vcount) ? CURHDR->index : -1;
938 if (op == OP_TOGGLE_READ) {
939 char buffer[LONG_STRING];
941 if (!Context->pattern
942 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
943 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
944 Context->pattern ? Context->pattern : ".*");
945 set_option (OPTHIDEREAD);
948 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
949 if (!*buf || strncmp (buf, ".*", 2) == 0)
950 snprintf (buf, sizeof (buf), "~A");
951 unset_option (OPTHIDEREAD);
953 p_delete(&Context->pattern);
954 Context->pattern = m_strdup(buf);
956 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
957 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
959 if (menu->oldcurrent >= 0) {
960 /* try to find what used to be the current message */
962 for (i = 0; i < Context->vcount; i++)
963 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
967 if (menu->current < 0)
972 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
973 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
974 mutt_draw_tree (Context);
975 menu->redraw = REDRAW_FULL;
977 if (Context->pattern)
978 mutt_message _("To view all messages, limit to \"all\".");
989 if (query_quadoption (OPT_QUIT, _("Quit Madmutt?")) == M_YES) {
992 oldcount = Context ? Context->msgcount : 0;
995 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
998 if (check == M_NEW_MAIL || check == M_REOPENED)
999 update_index (menu, Context, check, oldcount, index_hint);
1001 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1002 set_option (OPTSEARCHINVALID);
1009 clearok (stdscr, TRUE);
1010 menu->redraw = REDRAW_FULL;
1014 case OP_SEARCH_REVERSE:
1015 case OP_SEARCH_NEXT:
1016 case OP_SEARCH_OPPOSITE:
1020 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1021 menu->current = menu->oldcurrent;
1023 menu->redraw = REDRAW_MOTION;
1027 case OP_SORT_REVERSE:
1029 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1030 if (Context && Context->msgcount) {
1031 resort_index (menu);
1032 set_option (OPTSEARCHINVALID);
1041 if (tag && !option (OPTAUTOTAG)) {
1042 for (j = 0; j < Context->vcount; j++)
1043 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1044 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1047 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1048 Context->last_tag = CURHDR->tagged ? CURHDR :
1049 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1050 ? NULL : Context->last_tag);
1051 menu->redraw = REDRAW_STATUS;
1052 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1054 menu->redraw |= REDRAW_MOTION_RESYNCH;
1057 menu->redraw |= REDRAW_CURRENT;
1061 case OP_MAIN_TAG_PATTERN:
1065 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1066 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1069 case OP_MAIN_UNDELETE_PATTERN:
1075 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1077 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1079 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1082 case OP_MAIN_UNTAG_PATTERN:
1086 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1087 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1090 /* --------------------------------------------------------------------
1091 * The following operations can be performed inside of the pager.
1094 case OP_MAIN_IMAP_FETCH:
1095 if (Context->magic == M_IMAP)
1096 imap_check_mailbox (Context, &index_hint, 1);
1099 case OP_MAIN_SYNC_FOLDER:
1101 if (Context && !Context->msgcount)
1108 int oldvcount = Context->vcount;
1109 oldcount = Context->msgcount;
1113 /* calculate the number of messages _above_ the cursor,
1114 * so we can keep the cursor on the current message
1116 for (j = 0; j <= menu->current; j++) {
1117 if (Context->hdrs[Context->v2r[j]]->deleted)
1121 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1122 if (Context->vcount != oldvcount)
1123 menu->current -= dcount;
1124 set_option (OPTSEARCHINVALID);
1126 else if (check == M_NEW_MAIL || check == M_REOPENED)
1127 update_index (menu, Context, check, oldcount, index_hint);
1130 * do a sanity check even if mx_sync_mailbox failed.
1133 if (menu->current < 0 || menu->current >= Context->vcount)
1134 menu->current = ci_first_message ();
1137 /* check for a fatal error, or all messages deleted */
1141 /* if we were in the pager, redisplay the message */
1142 if (menu->menu == MENU_PAGER) {
1143 op = OP_DISPLAY_MESSAGE;
1147 menu->redraw = REDRAW_FULL;
1150 case OP_SIDEBAR_OPEN:
1151 case OP_MAIN_CHANGE_FOLDER:
1152 case OP_MAIN_CHANGE_FOLDER_READONLY:
1154 case OP_MAIN_CHANGE_GROUP:
1155 case OP_MAIN_CHANGE_GROUP_READONLY:
1157 if (attach_msg || option (OPTREADONLY) ||
1159 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1161 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1167 cp = _("Open mailbox in read-only mode");
1169 cp = _("Open mailbox");
1173 unset_option (OPTNEWS);
1174 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1175 set_option (OPTNEWS);
1176 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1179 cp = _("Open newsgroup in read-only mode");
1181 cp = _("Open newsgroup");
1182 nntp_buffy (buf, sizeof (buf));
1187 if (Context && Context->path)
1188 m_strcpy(buf, sizeof(buf), Context->path);
1189 if (op != OP_SIDEBAR_OPEN)
1190 buffy_next (buf, sizeof (buf));
1193 if (op == OP_SIDEBAR_OPEN) {
1194 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1196 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1197 if (menu->menu == MENU_PAGER) {
1198 op = OP_DISPLAY_MESSAGE;
1204 CLEARLINE (LINES - 1);
1209 if (option (OPTNEWS)) {
1210 unset_option (OPTNEWS);
1211 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1215 mutt_expand_path (buf, sizeof (buf));
1216 if (mx_get_magic (buf) <= 0) {
1217 mutt_error (_("%s is not a mailbox."), buf);
1220 m_strreplace(&CurrentFolder, buf);
1225 if (Context->compressinfo && Context->realpath)
1226 m_strreplace(&LastFolder, Context->realpath);
1228 m_strreplace(&LastFolder, Context->path);
1229 oldcount = Context ? Context->msgcount : 0;
1231 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1232 if (check == M_NEW_MAIL || check == M_REOPENED)
1233 update_index (menu, Context, check, oldcount, index_hint);
1235 set_option (OPTSEARCHINVALID);
1236 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1244 /* Set CurrentMenu to MENU_MAIN before executing any folder
1245 * hooks so that all the index menu functions are available to
1249 CurrentMenu = MENU_MAIN;
1250 mutt_folder_hook (buf);
1252 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1253 menu->current = ci_first_message ();
1257 sidebar_set_current (buf);
1260 /* buffy_check() must be done with mail-reader mode! */
1261 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1263 && (Context->magic ==
1264 M_NNTP)) ? IndexNewsHelp :
1267 mutt_clear_error ();
1268 buffy_check (0); /* force the buffy check after we have changed
1270 menu->redraw = REDRAW_FULL;
1271 set_option (OPTSEARCHINVALID);
1274 case OP_DISPLAY_MESSAGE:
1275 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1280 * toggle the weeding of headers so that a user can press the key
1281 * again while reading the message.
1283 if (op == OP_DISPLAY_HEADERS)
1284 toggle_option (OPTWEED);
1286 unset_option (OPTNEEDRESORT);
1288 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1289 mutt_uncollapse_thread (Context, CURHDR);
1290 mutt_set_virtual (Context);
1291 if (option (OPTUNCOLLAPSEJUMP))
1292 menu->current = mutt_thread_next_unread (Context, CURHDR);
1295 if (option (OPTPGPAUTODEC) &&
1296 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1297 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1299 if ((op = mutt_display_message (CURHDR)) == -1) {
1300 unset_option (OPTNEEDRESORT);
1304 menu->menu = MENU_PAGER;
1305 menu->oldcurrent = menu->current;
1311 if (menu->menu == MENU_MAIN && attach_msg) {
1316 if ((menu->menu == MENU_MAIN)
1317 && (query_quadoption (OPT_QUIT,
1318 _("Exit Madmutt without saving?")) == M_YES))
1321 mx_fastclose_mailbox (Context);
1333 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1334 /* if we were in the pager, redisplay the message */
1335 if (menu->menu == MENU_PAGER) {
1336 op = OP_DISPLAY_MESSAGE;
1340 menu->redraw = REDRAW_CURRENT;
1343 case OP_MAIN_BREAK_THREAD:
1349 if ((Sort & SORT_MASK) != SORT_THREADS)
1350 mutt_error (_("Threading is not enabled."));
1354 HEADER *oldcur = CURHDR;
1356 mutt_break_thread (CURHDR);
1357 mutt_sort_headers (Context, 1);
1358 menu->current = oldcur->virtual;
1361 Context->changed = 1;
1362 mutt_message _("Thread broken");
1364 if (menu->menu == MENU_PAGER) {
1365 op = OP_DISPLAY_MESSAGE;
1369 menu->redraw |= REDRAW_INDEX;
1373 case OP_MAIN_LINK_THREADS:
1379 if ((Sort & SORT_MASK) != SORT_THREADS)
1380 mutt_error (_("Threading is not enabled."));
1382 else if (!CURHDR->env->message_id)
1383 mutt_error (_("No Message-ID: header available to link thread"));
1385 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1386 mutt_error (_("First, please tag a message to be linked here"));
1389 HEADER *oldcur = CURHDR;
1391 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1393 mutt_sort_headers (Context, 1);
1394 menu->current = oldcur->virtual;
1396 Context->changed = 1;
1397 mutt_message _("Threads linked");
1400 mutt_error (_("No thread linked"));
1403 if (menu->menu == MENU_PAGER) {
1404 op = OP_DISPLAY_MESSAGE;
1408 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1411 case OP_MAIN_NEXT_UNDELETED:
1415 if (menu->current >= Context->vcount - 1) {
1416 if (menu->menu == MENU_MAIN)
1417 mutt_error (_("You are on the last message."));
1421 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1422 menu->current = menu->oldcurrent;
1423 if (menu->menu == MENU_MAIN)
1424 mutt_error (_("No undeleted messages."));
1426 else if (menu->menu == MENU_PAGER) {
1427 op = OP_DISPLAY_MESSAGE;
1431 menu->redraw = REDRAW_MOTION;
1438 if (menu->current >= Context->vcount - 1) {
1439 if (menu->menu == MENU_MAIN)
1440 mutt_error (_("You are on the last message."));
1445 if (menu->menu == MENU_PAGER) {
1446 op = OP_DISPLAY_MESSAGE;
1450 menu->redraw = REDRAW_MOTION;
1453 case OP_MAIN_PREV_UNDELETED:
1457 if (menu->current < 1) {
1458 mutt_error (_("You are on the first message."));
1462 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1463 menu->current = menu->oldcurrent;
1464 if (menu->menu == MENU_MAIN)
1465 mutt_error (_("No undeleted messages."));
1467 else if (menu->menu == MENU_PAGER) {
1468 op = OP_DISPLAY_MESSAGE;
1472 menu->redraw = REDRAW_MOTION;
1479 if (menu->current < 1) {
1480 if (menu->menu == MENU_MAIN)
1481 mutt_error (_("You are on the first message."));
1486 if (menu->menu == MENU_PAGER) {
1487 op = OP_DISPLAY_MESSAGE;
1491 menu->redraw = REDRAW_MOTION;
1494 case OP_DECRYPT_COPY:
1495 case OP_DECRYPT_SAVE:
1496 case OP_COPY_MESSAGE:
1498 case OP_DECODE_COPY:
1499 case OP_DECODE_SAVE:
1502 if (mutt_save_message (tag ? NULL : CURHDR,
1503 (op == OP_DECRYPT_SAVE) ||
1504 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1505 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1506 (op == OP_DECRYPT_SAVE)
1507 || (op == OP_DECRYPT_COPY)
1508 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1515 menu->redraw |= REDRAW_INDEX;
1516 else if (option (OPTRESOLVE)) {
1517 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1518 menu->current = menu->oldcurrent;
1519 menu->redraw |= REDRAW_CURRENT;
1522 menu->redraw |= REDRAW_MOTION_RESYNCH;
1525 menu->redraw |= REDRAW_CURRENT;
1529 case OP_MAIN_NEXT_NEW:
1530 case OP_MAIN_NEXT_UNREAD:
1531 case OP_MAIN_PREV_NEW:
1532 case OP_MAIN_PREV_UNREAD:
1533 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1534 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1537 int first_unread = -1;
1545 for (j = 0; j != Context->vcount; j++) {
1546 #define CURHDRi Context->hdrs[Context->v2r[i]]
1547 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1548 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1550 if (i > Context->vcount - 1) {
1551 mutt_message _("Search wrapped to top.");
1559 mutt_message _("Search wrapped to bottom.");
1561 i = Context->vcount - 1;
1565 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1566 if (UNREAD (CURHDRi) && first_unread == -1)
1568 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1571 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1572 if (first_unread == -1)
1574 if ((!CURHDRi->old) && first_new == -1)
1578 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1581 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1582 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1583 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1588 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1589 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1590 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1592 menu->current = first_new;
1593 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1594 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1595 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1596 && first_unread != -1)
1597 menu->current = first_unread;
1599 if (menu->current == -1) {
1600 menu->current = menu->oldcurrent;
1601 mutt_error ("%s%s.",
1602 (op == OP_MAIN_NEXT_NEW
1604 OP_MAIN_PREV_NEW) ? _("No new messages") :
1605 _("No unread messages"),
1606 Context->pattern ? _(" in this limited view") : "");
1608 else if (menu->menu == MENU_PAGER) {
1609 op = OP_DISPLAY_MESSAGE;
1613 menu->redraw = REDRAW_MOTION;
1616 case OP_FLAG_MESSAGE:
1622 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1625 for (j = 0; j < Context->vcount; j++) {
1626 if (Context->hdrs[Context->v2r[j]]->tagged)
1627 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1628 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1631 menu->redraw |= REDRAW_INDEX;
1634 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1635 if (option (OPTRESOLVE)) {
1636 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1637 menu->current = menu->oldcurrent;
1638 menu->redraw = REDRAW_CURRENT;
1641 menu->redraw = REDRAW_MOTION_RESYNCH;
1644 menu->redraw = REDRAW_CURRENT;
1646 menu->redraw |= REDRAW_STATUS;
1655 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1658 for (j = 0; j < Context->vcount; j++) {
1659 if (Context->hdrs[Context->v2r[j]]->tagged) {
1660 if (Context->hdrs[Context->v2r[j]]->read ||
1661 Context->hdrs[Context->v2r[j]]->old)
1662 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1665 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1669 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1672 if (CURHDR->read || CURHDR->old)
1673 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1675 mutt_set_flag (Context, CURHDR, M_READ, 1);
1677 if (option (OPTRESOLVE)) {
1678 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1679 menu->current = menu->oldcurrent;
1680 menu->redraw = REDRAW_CURRENT;
1683 menu->redraw = REDRAW_MOTION_RESYNCH;
1686 menu->redraw = REDRAW_CURRENT;
1687 menu->redraw |= REDRAW_STATUS;
1691 case OP_TOGGLE_WRITE:
1694 if (mx_toggle_write (Context) == 0)
1695 menu->redraw |= REDRAW_STATUS;
1698 case OP_MAIN_NEXT_THREAD:
1699 case OP_MAIN_NEXT_SUBTHREAD:
1700 case OP_MAIN_PREV_THREAD:
1701 case OP_MAIN_PREV_SUBTHREAD:
1706 case OP_MAIN_NEXT_THREAD:
1707 menu->current = mutt_next_thread (CURHDR);
1710 case OP_MAIN_NEXT_SUBTHREAD:
1711 menu->current = mutt_next_subthread (CURHDR);
1714 case OP_MAIN_PREV_THREAD:
1715 menu->current = mutt_previous_thread (CURHDR);
1718 case OP_MAIN_PREV_SUBTHREAD:
1719 menu->current = mutt_previous_subthread (CURHDR);
1723 if (menu->current < 0) {
1724 menu->current = menu->oldcurrent;
1725 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1726 mutt_error (_("No more threads."));
1729 mutt_error (_("You are on the first thread."));
1731 else if (menu->menu == MENU_PAGER) {
1732 op = OP_DISPLAY_MESSAGE;
1736 menu->redraw = REDRAW_MOTION;
1739 case OP_MAIN_PARENT_MESSAGE:
1744 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1745 menu->current = menu->oldcurrent;
1747 else if (menu->menu == MENU_PAGER) {
1748 op = OP_DISPLAY_MESSAGE;
1752 menu->redraw = REDRAW_MOTION;
1755 case OP_MAIN_SET_FLAG:
1756 case OP_MAIN_CLEAR_FLAG:
1762 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1764 menu->redraw = REDRAW_STATUS;
1766 menu->redraw |= REDRAW_INDEX;
1767 else if (option (OPTRESOLVE)) {
1768 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1769 menu->current = menu->oldcurrent;
1770 menu->redraw |= REDRAW_CURRENT;
1773 menu->redraw |= REDRAW_MOTION_RESYNCH;
1776 menu->redraw |= REDRAW_CURRENT;
1780 case OP_MAIN_COLLAPSE_THREAD:
1784 if ((Sort & SORT_MASK) != SORT_THREADS) {
1785 mutt_error (_("Threading is not enabled."));
1790 if (CURHDR->collapsed) {
1791 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1792 mutt_set_virtual (Context);
1793 if (option (OPTUNCOLLAPSEJUMP))
1794 menu->current = mutt_thread_next_unread (Context, CURHDR);
1796 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1797 menu->current = mutt_collapse_thread (Context, CURHDR);
1798 mutt_set_virtual (Context);
1801 mutt_error (_("Thread contains unread messages."));
1806 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1810 case OP_MAIN_COLLAPSE_ALL:
1814 if ((Sort & SORT_MASK) != SORT_THREADS) {
1815 mutt_error (_("Threading is not enabled."));
1822 THREAD *thread, *top;
1825 if (CURHDR->collapsed)
1826 final = mutt_uncollapse_thread (Context, CURHDR);
1827 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1828 final = mutt_collapse_thread (Context, CURHDR);
1830 final = CURHDR->virtual;
1832 base = Context->hdrs[Context->v2r[final]];
1834 top = Context->tree;
1835 Context->collapsed = !Context->collapsed;
1836 while ((thread = top) != NULL) {
1837 while (!thread->message)
1838 thread = thread->child;
1839 h = thread->message;
1841 if (h->collapsed != Context->collapsed) {
1843 mutt_uncollapse_thread (Context, h);
1844 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1845 mutt_collapse_thread (Context, h);
1850 mutt_set_virtual (Context);
1851 for (j = 0; j < Context->vcount; j++) {
1852 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1858 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1862 /* --------------------------------------------------------------------
1863 * These functions are invoked directly from the internal-pager
1866 case OP_BOUNCE_MESSAGE:
1871 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1874 case OP_CREATE_ALIAS:
1876 mutt_create_alias (Context
1877 && Context->vcount ? CURHDR->env : NULL, NULL);
1878 MAYBE_REDRAW (menu->redraw);
1879 menu->redraw |= REDRAW_CURRENT;
1884 mutt_query_menu (NULL, 0);
1885 MAYBE_REDRAW (menu->redraw);
1888 case OP_PURGE_MESSAGE:
1895 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1898 mutt_tag_set_flag (M_DELETE, 1);
1899 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1900 if (option (OPTDELETEUNTAG))
1901 mutt_tag_set_flag (M_TAG, 0);
1902 menu->redraw = REDRAW_INDEX;
1905 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1906 mutt_set_flag (Context, CURHDR, M_PURGED,
1907 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1908 if (option (OPTDELETEUNTAG))
1909 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1910 if (option (OPTRESOLVE)) {
1911 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1912 menu->current = menu->oldcurrent;
1913 menu->redraw = REDRAW_CURRENT;
1915 else if (menu->menu == MENU_PAGER) {
1916 op = OP_DISPLAY_MESSAGE;
1920 menu->redraw |= REDRAW_MOTION_RESYNCH;
1923 menu->redraw = REDRAW_CURRENT;
1925 menu->redraw |= REDRAW_STATUS;
1928 case OP_DELETE_THREAD:
1929 case OP_DELETE_SUBTHREAD:
1935 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1937 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1938 op == OP_DELETE_THREAD ? 0 : 1);
1941 if (option (OPTDELETEUNTAG))
1942 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1943 op == OP_DELETE_THREAD ? 0 : 1);
1944 if (option (OPTRESOLVE))
1945 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1946 menu->current = menu->oldcurrent;
1947 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1953 if (Context && Context->magic == M_NNTP) {
1954 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1955 ((NNTP_DATA *) Context->data)->group))
1956 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1961 case OP_DISPLAY_ADDRESS:
1965 mutt_display_address (CURHDR->env);
1968 case OP_ENTER_COMMAND:
1970 CurrentMenu = MENU_MAIN;
1971 mutt_enter_command ();
1972 mutt_check_rescore (Context);
1973 if (option (OPTFORCEREDRAWINDEX))
1974 menu->redraw = REDRAW_FULL;
1975 unset_option (OPTFORCEREDRAWINDEX);
1976 unset_option (OPTFORCEREDRAWPAGER);
1979 case OP_EDIT_MESSAGE:
1986 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1988 if (option (OPTPGPAUTODEC)
1989 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1990 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1991 mutt_edit_message (Context, tag ? NULL : CURHDR);
1992 menu->redraw = REDRAW_FULL;
1996 case OP_FORWARD_MESSAGE:
2002 if (option (OPTPGPAUTODEC) &&
2003 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2004 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2005 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2006 menu->redraw = REDRAW_FULL;
2010 case OP_FORGET_PASSPHRASE:
2011 crypt_forget_passphrase ();
2014 case OP_GROUP_REPLY:
2020 if (option (OPTPGPAUTODEC) &&
2021 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2022 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2024 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2025 tag ? NULL : CURHDR);
2026 menu->redraw = REDRAW_FULL;
2035 if (option (OPTPGPAUTODEC) &&
2036 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2037 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2039 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2040 tag ? NULL : CURHDR);
2041 menu->redraw = REDRAW_FULL;
2047 ci_send_message (0, NULL, NULL, Context, NULL);
2048 menu->redraw = REDRAW_FULL;
2053 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2054 menu->redraw = REDRAW_FULL;
2058 case OP_EXTRACT_KEYS:
2061 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2062 menu->redraw = REDRAW_FULL;
2066 case OP_CHECK_TRADITIONAL:
2069 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2070 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2072 if (menu->menu == MENU_PAGER) {
2073 op = OP_DISPLAY_MESSAGE;
2082 mutt_pipe_message (tag ? NULL : CURHDR);
2083 /* in an IMAP folder index with imap_peek=no, piping could change
2084 * * new or old messages status to read. Redraw what's needed.
2086 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2087 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2089 MAYBE_REDRAW (menu->redraw);
2096 mutt_print_message (tag ? NULL : CURHDR);
2097 /* in an IMAP folder index with imap_peek=no, piping could change
2098 * * new or old messages status to read. Redraw what's needed.
2100 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2101 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2105 case OP_MAIN_READ_THREAD:
2106 case OP_MAIN_READ_SUBTHREAD:
2112 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2114 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2115 op == OP_MAIN_READ_THREAD ? 0 : 1);
2118 if (option (OPTRESOLVE)) {
2119 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2120 mutt_next_thread (CURHDR) :
2121 mutt_next_subthread (CURHDR))) == -1)
2122 menu->current = menu->oldcurrent;
2124 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2128 case OP_RECALL_MESSAGE:
2131 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2132 menu->redraw = REDRAW_FULL;
2142 for (j = 0; j < Context->vcount; j++) {
2143 if (Context->hdrs[Context->v2r[j]]->tagged)
2144 mutt_resend_message (NULL, Context,
2145 Context->hdrs[Context->v2r[j]]);
2149 mutt_resend_message (NULL, Context, CURHDR);
2151 menu->redraw = REDRAW_FULL;
2157 case OP_FORWARD_TO_GROUP:
2160 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2161 Context && Context->msgcount == 0) {
2162 mutt_error (_("There are no messages."));
2165 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2166 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2167 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2168 _("Reply by mail as poster prefers?")) !=
2170 if (Context && Context->magic == M_NNTP
2171 && !((NNTP_DATA *) Context->data)->allowed
2172 && query_quadoption (OPT_TOMODERATED,
2174 ("Posting to this group not allowed, may be moderated. Continue?"))
2178 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2181 if (op == OP_FOLLOWUP)
2182 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2183 tag ? NULL : CURHDR);
2185 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2186 tag ? NULL : CURHDR);
2188 menu->redraw = REDRAW_FULL;
2199 if (option (OPTPGPAUTODEC) &&
2200 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2201 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2203 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2204 menu->redraw = REDRAW_FULL;
2207 case OP_SHELL_ESCAPE:
2209 mutt_shell_escape ();
2210 MAYBE_REDRAW (menu->redraw);
2214 case OP_TAG_SUBTHREAD:
2218 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2219 op == OP_TAG_THREAD ? 0 : 1);
2222 if (option (OPTRESOLVE)) {
2223 menu->current = mutt_next_thread (CURHDR);
2225 if (menu->current == -1)
2226 menu->current = menu->oldcurrent;
2228 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2238 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2241 mutt_tag_set_flag (M_DELETE, 0);
2242 mutt_tag_set_flag (M_PURGED, 0);
2243 menu->redraw = REDRAW_INDEX;
2246 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2247 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2248 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2250 menu->redraw = REDRAW_MOTION_RESYNCH;
2253 menu->redraw = REDRAW_CURRENT;
2255 menu->redraw |= REDRAW_STATUS;
2258 case OP_UNDELETE_THREAD:
2259 case OP_UNDELETE_SUBTHREAD:
2265 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2267 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2268 op == OP_UNDELETE_THREAD ? 0 : 1)
2269 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2270 op == OP_UNDELETE_THREAD ? 0 : 1);
2273 if (option (OPTRESOLVE)) {
2274 if (op == OP_UNDELETE_THREAD)
2275 menu->current = mutt_next_thread (CURHDR);
2277 menu->current = mutt_next_subthread (CURHDR);
2279 if (menu->current == -1)
2280 menu->current = menu->oldcurrent;
2282 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2291 if (option (OPTFORCEBUFFYCHECK))
2294 menu->redraw = REDRAW_FULL;
2297 case OP_VIEW_ATTACHMENTS:
2300 mutt_view_attachments (CURHDR);
2301 if (CURHDR->attach_del)
2302 Context->changed = 1;
2303 menu->redraw = REDRAW_FULL;
2313 case OP_REBUILD_CACHE:
2314 mx_rebuild_cache ();
2317 case OP_SIDEBAR_SCROLL_UP:
2318 case OP_SIDEBAR_SCROLL_DOWN:
2319 case OP_SIDEBAR_NEXT:
2320 case OP_SIDEBAR_PREV:
2321 case OP_SIDEBAR_NEXT_NEW:
2322 case OP_SIDEBAR_PREV_NEW:
2323 sidebar_scroll (op, menu->menu);
2326 if (menu->menu == MENU_MAIN)
2327 km_error_key (MENU_MAIN);
2330 if (menu->menu == MENU_PAGER) {
2331 menu->menu = MENU_MAIN;
2332 menu->redraw = REDRAW_FULL;
2334 set_option (OPTWEED); /* turn header weeding back on. */
2343 /* Close all open IMAP connections */
2346 /* Close all open NNTP connections */
2354 mutt_menuDestroy (&menu);
2358 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2365 for (color = ColorIndexList; color; color = color->next)
2366 if (mutt_pattern_exec
2367 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2368 curhdr->pair = color->pair;
2371 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];