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>
29 #include <lib-lib/debug.h>
39 #include "recvattach.h"
46 #include <imap/imap_private.h>
48 #include <lib-crypt/crypt.h>
51 #include "nntp/nntp.h"
55 #include "mutt_sasl.h"
58 static const char *No_mailbox_is_open = N_("No mailbox is open.");
59 static const char *There_are_no_messages = N_("There are no messages.");
60 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
61 static const char *Function_not_permitted_in_attach_message_mode =
62 N_("Function not permitted in attach-message mode.");
63 static const char *No_visible = N_("No visible messages.");
65 #define CHECK_IN_MAILBOX if (!Context) \
68 mutt_error (_(No_mailbox_is_open)); \
72 #define CHECK_MSGCOUNT if (!Context) \
75 mutt_error(_(No_mailbox_is_open)); \
78 else if (!Context->msgcount) \
81 mutt_error(_(There_are_no_messages)); \
85 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
88 mutt_error(_(No_visible)); \
93 #define CHECK_READONLY if (Context->readonly) \
96 mutt_error(_(Mailbox_is_read_only)); \
100 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
103 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
107 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
108 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
109 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
110 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
112 extern size_t UngetCount;
114 void index_make_entry (char *s, ssize_t l, struct menu_t * menu, int num)
117 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
118 int edgemsgno, reverse = Sort & SORT_REVERSE;
119 HEADER *h = Context->hdrs[Context->v2r[num]];
122 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
123 flag |= M_FORMAT_TREE; /* display the thread tree */
124 if (h->display_subject)
125 flag |= M_FORMAT_FORCESUBJ;
128 if (menu->top + menu->pagelen > menu->max)
129 edgemsgno = Context->v2r[menu->max - 1];
131 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
134 edgemsgno = Context->v2r[menu->top];
136 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
140 /* if no ancestor is visible on current screen, provisionally force
142 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
144 flag |= M_FORMAT_FORCESUBJ;
147 else if (tmp->message->virtual >= 0)
150 if (flag & M_FORMAT_FORCESUBJ) {
151 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
155 /* ...but if a previous sibling is available, don't force it */
156 if (reverse ? tmp->message->msgno >
157 edgemsgno : tmp->message->msgno < edgemsgno)
159 else if (tmp->message->virtual >= 0) {
160 flag &= ~M_FORMAT_FORCESUBJ;
168 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
171 int index_color (int index_no)
173 HEADER *h = Context->hdrs[Context->v2r[index_no]];
178 mutt_set_header_color (Context, h);
182 static int ci_next_undeleted (int msgno)
186 for (i = msgno + 1; i < Context->vcount; i++)
187 if (!Context->hdrs[Context->v2r[i]]->deleted)
192 static int ci_previous_undeleted (int msgno)
196 for (i = msgno - 1; i >= 0; i--)
197 if (!Context->hdrs[Context->v2r[i]]->deleted)
202 /* Return the index of the first new message, or failing that, the first
205 static int ci_first_message (void)
209 if (Context && Context->msgcount) {
210 for (i = 0; i < Context->vcount; i++) {
211 if (!Context->hdrs[Context->v2r[i]]->read &&
212 !Context->hdrs[Context->v2r[i]]->deleted) {
213 if (!Context->hdrs[Context->v2r[i]]->old)
222 /* If Sort is reverse and not threaded, the latest message is first.
223 * If Sort is threaded, the latest message is first iff exactly one
224 * of Sort and SortAux are reverse.
226 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
227 ((Sort & SORT_MASK) == SORT_THREADS &&
228 ((Sort ^ SortAux) & SORT_REVERSE)))
231 return (Context->vcount ? Context->vcount - 1 : 0);
236 /* This should be in mx.c, but it only gets used here. */
237 static int mx_toggle_write (CONTEXT * ctx)
243 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
248 if (ctx->dontwrite) {
250 mutt_message (_("Changes to folder will be written on folder exit."));
254 mutt_message (_("Changes to folder will not be written."));
260 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
261 int oldcount, int index_hint)
263 /* store pointers to the newly added messages */
264 HEADER **save_new = NULL;
267 /* take note of the current message */
269 if (menu->current < Context->vcount)
270 menu->oldcurrent = index_hint;
272 oldcount = 0; /* invalid message number! */
275 /* We are in a limited view. Check if the new message(s) satisfy
276 * the limit criteria. If they do, set their virtual msgno so that
277 * they will be visible in the limited view */
278 if (Context->pattern) {
279 #define THIS_BODY Context->hdrs[j]->content
280 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
281 if (mutt_pattern_exec
282 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
284 Context->hdrs[j]->virtual = Context->vcount;
285 Context->v2r[Context->vcount] = j;
286 Context->hdrs[j]->limited = 1;
289 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
295 /* save the list of new messages */
296 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
297 save_new = p_new(HEADER*, Context->msgcount - oldcount);
298 for (j = oldcount; j < Context->msgcount; j++)
299 save_new[j - oldcount] = Context->hdrs[j];
302 /* if the mailbox was reopened, need to rethread from scratch */
303 mutt_sort_headers (Context, (check == M_REOPENED));
305 /* uncollapse threads with new mail */
306 if ((Sort & SORT_MASK) == SORT_THREADS) {
307 if (check == M_REOPENED) {
310 Context->collapsed = 0;
312 for (h = Context->tree; h; h = h->next) {
313 for (c = h; !c->message; c = c->child);
314 mutt_uncollapse_thread (Context, c->message);
316 mutt_set_virtual (Context);
319 for (j = 0; j < Context->msgcount - oldcount; j++) {
322 for (k = 0; k < Context->msgcount; k++) {
323 HEADER *h = Context->hdrs[k];
325 if (h == save_new[j] && (!Context->pattern || h->limited))
326 mutt_uncollapse_thread (Context, h);
330 mutt_set_virtual (Context);
336 /* restore the current message to the message it was pointing to */
337 for (j = 0; j < Context->vcount; j++) {
338 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
345 if (menu->current < 0)
346 menu->current = ci_first_message ();
349 static void resort_index (MUTTMENU * menu)
352 HEADER *current = CURHDR;
355 mutt_sort_headers (Context, 0);
356 /* Restore the current message */
358 for (i = 0; i < Context->vcount; i++) {
359 if (Context->hdrs[Context->v2r[i]] == current) {
365 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
366 menu->current = mutt_parent_message (Context, current);
368 if (menu->current < 0)
369 menu->current = ci_first_message ();
371 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
374 struct mapping_t IndexHelp[] = {
375 {N_("Quit"), OP_QUIT},
376 {N_("Del"), OP_DELETE},
377 {N_("Undel"), OP_UNDELETE},
378 {N_("Save"), OP_SAVE},
379 {N_("Mail"), OP_MAIL},
380 {N_("Reply"), OP_REPLY},
381 {N_("Group"), OP_GROUP_REPLY},
382 {N_("Help"), OP_HELP},
387 struct mapping_t IndexNewsHelp[] = {
388 {N_("Quit"), OP_QUIT},
389 {N_("Del"), OP_DELETE},
390 {N_("Undel"), OP_UNDELETE},
391 {N_("Save"), OP_SAVE},
392 {N_("Post"), OP_POST},
393 {N_("Followup"), OP_FOLLOWUP},
394 {N_("Catchup"), OP_CATCHUP},
395 {N_("Help"), OP_HELP},
400 /* This function handles the message index window as well as commands returned
401 * from the pager (MENU_PAGER).
403 int mutt_index_menu (void)
405 char buf[LONG_STRING], helpstr[SHORT_STRING];
408 int done = 0; /* controls when to exit the "event" loop */
410 int tag = 0; /* has the tag-prefix command been pressed? */
415 char *cp; /* temporary variable. */
416 int index_hint; /* used to restore cursor position */
417 int do_buffy_notify = 1;
418 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
419 int attach_msg = option (OPTATTACHMSG);
421 menu = mutt_new_menu ();
422 menu->menu = MENU_MAIN;
424 menu->pagelen = LINES - 3;
425 menu->make_entry = (void *) index_make_entry;
426 menu->color = index_color;
427 menu->current = ci_first_message ();
428 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
431 && (Context->magic ==
432 M_NNTP)) ? IndexNewsHelp :
437 buffy_check (0); /* force the buffy check after we enter the folder */
438 /* record folder we open to place sidebar indicator properly */
439 if (Context && Context->path)
440 sidebar_set_current (Context->path);
444 tag = 0; /* clear the tag-prefix */
446 menu->max = Context ? Context->vcount : 0;
447 oldcount = Context ? Context->msgcount : 0;
449 /* check if we need to resort the index because just about
450 * any 'op' below could do mutt_enter_command(), either here or
451 * from any new menu launched, and change $sort/$sort_aux
453 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
456 if (option (OPTREDRAWTREE) && Context && Context->msgcount
457 && (Sort & SORT_MASK) == SORT_THREADS) {
458 mutt_draw_tree (Context);
459 menu->redraw |= REDRAW_STATUS;
460 unset_option (OPTREDRAWTREE);
463 if (Context && !attach_msg) {
466 /* check for new mail in the mailbox. If nonzero, then something has
467 * changed about the file (either we got new mail or the file was
468 * modified underneath us.)
471 imap_allow_reopen (Context);
473 index_hint = (Context->vcount && menu->current >= 0
474 && menu->current < Context->vcount) ? CURHDR->index : 0;
476 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
477 if (!Context->path) {
478 /* fatal error occurred */
480 menu->redraw = REDRAW_FULL;
482 set_option (OPTSEARCHINVALID);
484 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
485 update_index (menu, Context, check, oldcount, index_hint);
487 /* notify the user of new mail */
488 if (check == M_REOPENED)
490 ("Mailbox was externally modified. Flags may be wrong."));
491 else if (check == M_NEW_MAIL) {
492 /* on new mail: redraw sidebar */
493 sidebar_draw (CurrentMenu);
494 mutt_message (_("New mail in this mailbox."));
496 if (option (OPTBEEPNEW))
499 else if (check == M_FLAGS)
500 mutt_message (_("Mailbox was externally modified."));
502 /* avoid the message being overwritten by buffy */
505 menu->redraw = REDRAW_FULL;
506 menu->max = Context->vcount;
508 set_option (OPTSEARCHINVALID);
513 imap_disallow_reopen (Context);
516 /* check for new mail in the incoming folders */
518 if ((newcount = buffy_check (0)) != oldcount) {
519 menu->redraw |= REDRAW_STATUS;
520 menu->redraw |= REDRAW_SIDEBAR;
522 if (do_buffy_notify) {
523 if (buffy_notify () && option (OPTBEEPNEW))
532 if (menu->redraw & REDRAW_SIDEBAR)
533 sidebar_draw (menu->menu);
534 if (menu->redraw & REDRAW_FULL) {
535 menu_redraw_full (menu);
536 sidebar_draw (menu->menu);
540 if (menu->menu == MENU_MAIN) {
541 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
542 menu_check_recenter (menu);
544 if (menu->redraw & REDRAW_INDEX) {
545 menu_redraw_index (menu);
546 menu->redraw |= REDRAW_STATUS;
548 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
549 menu_redraw_motion (menu);
550 else if (menu->redraw & REDRAW_CURRENT)
551 menu_redraw_current (menu);
554 if (menu->redraw & REDRAW_STATUS) {
555 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
556 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
557 sidebar_draw_frames();
558 SETCOLOR (MT_COLOR_STATUS);
559 BKGDSET (MT_COLOR_STATUS);
560 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
561 mutt_paddstr (COLS-SW, buf);
562 SETCOLOR (MT_COLOR_NORMAL);
563 BKGDSET (MT_COLOR_NORMAL);
564 sidebar_set_buffystats (Context);
565 menu->redraw &= ~REDRAW_STATUS;
566 if (option (OPTXTERMSETTITLES)) {
567 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
568 mutt_xterm_set_title (buf);
569 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
570 mutt_xterm_set_icon (buf);
575 if (menu->current < menu->max)
576 menu->oldcurrent = menu->current;
578 menu->oldcurrent = -1;
580 if (option (OPTARROWCURSOR))
581 move (menu->current - menu->top + menu->offset, 2);
582 else if (option (OPTBRAILLEFRIENDLY))
583 move (menu->current - menu->top + menu->offset, 0);
585 move (menu->current - menu->top + menu->offset, COLS - 1);
588 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
591 mutt_resize_screen ();
592 menu->redraw = REDRAW_FULL;
593 menu->menu = MENU_MAIN;
595 menu->top = 0; /* so we scroll the right amount */
597 * force a real complete redraw. clrtobot() doesn't seem to be able
598 * to handle every case without this.
600 clearok (stdscr, TRUE);
605 op = km_dokey (MENU_MAIN);
607 debug_print (4, ("Got op %d\n", op));
610 continue; /* either user abort or timeout */
614 /* special handling for the tag-prefix function */
615 if (op == OP_TAG_PREFIX) {
617 mutt_error (_("No mailbox is open."));
622 if (!Context->tagged) {
623 mutt_error (_("No tagged messages."));
629 /* give visual indication that the next command is a tag- command */
630 mvaddstr (LINES - 1, 0, "tag-");
633 /* get the real command */
634 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
635 /* abort tag sequence */
636 CLEARLINE (LINES - 1);
640 else if (option (OPTAUTOTAG) && Context && Context->tagged)
643 if (op == OP_TAG_PREFIX_COND) {
645 mutt_error (_("No mailbox is open."));
650 if (!Context->tagged) {
653 while (UngetCount > 0) {
655 if (tmp.op == OP_END_COND)
658 mutt_message (_("Nothing to do."));
664 /* give visual indication that the next command is a tag- command */
665 mvaddstr (LINES - 1, 0, "tag-");
668 /* get the real command */
669 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
670 /* abort tag sequence */
671 CLEARLINE (LINES - 1);
679 if (menu->current < menu->max)
680 menu->oldcurrent = menu->current;
682 menu->oldcurrent = -1;
684 mutt_curs_set (1); /* fallback from the pager */
688 unset_option (OPTNEWS); /* for any case */
693 /* ----------------------------------------------------------------------
698 menu_bottom_page (menu);
701 menu_first_entry (menu);
704 menu_middle_page (menu);
710 menu_half_down (menu);
713 menu_next_line (menu);
716 menu_prev_line (menu);
719 menu_next_page (menu);
722 menu_prev_page (menu);
725 menu_last_entry (menu);
728 menu_top_page (menu);
731 menu_current_top (menu);
733 case OP_CURRENT_MIDDLE:
734 menu_current_middle (menu);
736 case OP_CURRENT_BOTTOM:
737 menu_current_bottom (menu);
744 if (Context->magic == M_NNTP) {
747 if (op == OP_GET_MESSAGE) {
749 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
754 string_list_t *ref = CURHDR->env->references;
757 mutt_error (_("Article has no parent reference!"));
761 m_strcpy(buf, sizeof(buf), ref->data);
763 if (!Context->id_hash)
764 Context->id_hash = mutt_make_id_hash (Context);
765 if ((h = hash_find (Context->id_hash, buf))) {
766 if (h->virtual != -1) {
767 menu->current = h->virtual;
768 menu->redraw = REDRAW_MOTION_RESYNCH;
770 else if (h->collapsed) {
771 mutt_uncollapse_thread (Context, h);
772 mutt_set_virtual (Context);
773 menu->current = h->virtual;
774 menu->redraw = REDRAW_MOTION_RESYNCH;
777 mutt_error (_("Message not visible in limited view."));
780 if (nntp_check_msgid (Context, buf) == 0) {
781 h = Context->hdrs[Context->msgcount - 1];
782 mutt_sort_headers (Context, 0);
783 menu->current = h->virtual;
784 menu->redraw = REDRAW_FULL;
787 mutt_error (_("Article %s not found on server"), buf);
792 case OP_GET_CHILDREN:
793 case OP_RECONSTRUCT_THREAD:
795 if (Context->magic == M_NNTP) {
797 int old = CURHDR->index;
799 if (!CURHDR->env->message_id) {
800 mutt_error (_("No Message-ID. Unable to perform operation"));
805 if (!Context->id_hash)
806 Context->id_hash = mutt_make_id_hash (Context);
807 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
809 if (op == OP_RECONSTRUCT_THREAD) {
810 string_list_t *ref = CURHDR->env->references;
813 nntp_check_msgid (Context, ref->data);
814 /* the last msgid in References is the root message */
816 m_strcpy(buf, sizeof(buf), ref->data);
820 mutt_message (_("Check for children of message..."));
822 if (nntp_check_children (Context, buf) == 0) {
823 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
824 h = hash_find (Context->id_hash, buf);
825 /* if the root message was retrieved, move to it */
827 menu->current = h->virtual;
828 else /* try to restore old position */
829 for (i = 0; i < Context->msgcount; i++)
830 if (Context->hdrs[i]->index == old) {
831 menu->current = Context->hdrs[i]->virtual;
832 /* As an added courtesy, recenter the menu
833 * with the current entry at the middle of the screen */
834 menu_check_recenter (menu);
835 menu_current_middle (menu);
838 menu->redraw = REDRAW_FULL;
848 if (isdigit (LastKey))
849 mutt_ungetch (LastKey, 0);
851 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
855 if (!isdigit ((unsigned char) buf[0])) {
856 mutt_error (_("Argument must be a message number."));
862 if (i > 0 && i <= Context->msgcount) {
863 for (j = i - 1; j < Context->msgcount; j++) {
864 if (Context->hdrs[j]->virtual != -1)
867 if (j >= Context->msgcount) {
868 for (j = i - 2; j >= 0; j--) {
869 if (Context->hdrs[j]->virtual != -1)
875 menu->current = Context->hdrs[j]->virtual;
876 if (menu->menu == MENU_PAGER) {
877 op = OP_DISPLAY_MESSAGE;
881 menu->redraw = REDRAW_MOTION;
884 mutt_error (_("That message is not visible."));
887 mutt_error (_("Invalid message number."));
891 /* --------------------------------------------------------------------
892 * `index' specific commands
895 case OP_MAIN_DELETE_PATTERN:
901 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
904 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
905 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
908 case OP_MAIN_FETCH_MAIL:
912 menu->redraw = REDRAW_FULL;
917 mutt_help (MENU_MAIN);
918 menu->redraw = REDRAW_FULL;
921 case OP_MAIN_SHOW_LIMIT:
923 if (!Context->pattern)
924 mutt_message (_("No limit pattern is in effect."));
929 /* i18n: ask for a limit to apply */
930 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
931 mutt_message ("%s", buffer);
939 menu->oldcurrent = (Context->vcount && menu->current >= 0
941 Context->vcount) ? CURHDR->index : -1;
942 if (op == OP_TOGGLE_READ) {
943 char buffer[LONG_STRING];
945 if (!Context->pattern
946 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
947 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
948 Context->pattern ? Context->pattern : ".*");
949 set_option (OPTHIDEREAD);
952 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
953 if (!*buf || strncmp (buf, ".*", 2) == 0)
954 snprintf (buf, sizeof (buf), "~A");
955 unset_option (OPTHIDEREAD);
957 p_delete(&Context->pattern);
958 Context->pattern = m_strdup(buf);
960 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
961 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
963 if (menu->oldcurrent >= 0) {
964 /* try to find what used to be the current message */
966 for (i = 0; i < Context->vcount; i++)
967 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
971 if (menu->current < 0)
976 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
977 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
978 mutt_draw_tree (Context);
979 menu->redraw = REDRAW_FULL;
981 if (Context->pattern)
982 mutt_message _("To view all messages, limit to \"all\".");
993 if (query_quadoption (OPT_QUIT, _("Quit Madmutt?")) == M_YES) {
996 oldcount = Context ? Context->msgcount : 0;
999 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1002 if (check == M_NEW_MAIL || check == M_REOPENED)
1003 update_index (menu, Context, check, oldcount, index_hint);
1005 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1006 set_option (OPTSEARCHINVALID);
1013 clearok (stdscr, TRUE);
1014 menu->redraw = REDRAW_FULL;
1018 case OP_SEARCH_REVERSE:
1019 case OP_SEARCH_NEXT:
1020 case OP_SEARCH_OPPOSITE:
1024 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1025 menu->current = menu->oldcurrent;
1027 menu->redraw = REDRAW_MOTION;
1031 case OP_SORT_REVERSE:
1033 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1034 if (Context && Context->msgcount) {
1035 resort_index (menu);
1036 set_option (OPTSEARCHINVALID);
1045 if (tag && !option (OPTAUTOTAG)) {
1046 for (j = 0; j < Context->vcount; j++)
1047 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1048 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1051 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1052 Context->last_tag = CURHDR->tagged ? CURHDR :
1053 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1054 ? NULL : Context->last_tag);
1055 menu->redraw = REDRAW_STATUS;
1056 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1058 menu->redraw |= REDRAW_MOTION_RESYNCH;
1061 menu->redraw |= REDRAW_CURRENT;
1065 case OP_MAIN_TAG_PATTERN:
1069 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1070 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1073 case OP_MAIN_UNDELETE_PATTERN:
1079 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1081 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1083 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1086 case OP_MAIN_UNTAG_PATTERN:
1090 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1091 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1094 /* --------------------------------------------------------------------
1095 * The following operations can be performed inside of the pager.
1098 case OP_MAIN_IMAP_FETCH:
1099 if (Context->magic == M_IMAP)
1100 imap_check_mailbox (Context, &index_hint, 1);
1103 case OP_MAIN_SYNC_FOLDER:
1105 if (Context && !Context->msgcount)
1112 int oldvcount = Context->vcount;
1113 oldcount = Context->msgcount;
1117 /* calculate the number of messages _above_ the cursor,
1118 * so we can keep the cursor on the current message
1120 for (j = 0; j <= menu->current; j++) {
1121 if (Context->hdrs[Context->v2r[j]]->deleted)
1125 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1126 if (Context->vcount != oldvcount)
1127 menu->current -= dcount;
1128 set_option (OPTSEARCHINVALID);
1130 else if (check == M_NEW_MAIL || check == M_REOPENED)
1131 update_index (menu, Context, check, oldcount, index_hint);
1134 * do a sanity check even if mx_sync_mailbox failed.
1137 if (menu->current < 0 || menu->current >= Context->vcount)
1138 menu->current = ci_first_message ();
1141 /* check for a fatal error, or all messages deleted */
1145 /* if we were in the pager, redisplay the message */
1146 if (menu->menu == MENU_PAGER) {
1147 op = OP_DISPLAY_MESSAGE;
1151 menu->redraw = REDRAW_FULL;
1154 case OP_SIDEBAR_OPEN:
1155 case OP_MAIN_CHANGE_FOLDER:
1156 case OP_MAIN_CHANGE_FOLDER_READONLY:
1158 case OP_MAIN_CHANGE_GROUP:
1159 case OP_MAIN_CHANGE_GROUP_READONLY:
1161 if (attach_msg || option (OPTREADONLY) ||
1163 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1165 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1171 cp = _("Open mailbox in read-only mode");
1173 cp = _("Open mailbox");
1177 unset_option (OPTNEWS);
1178 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1179 set_option (OPTNEWS);
1180 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1183 cp = _("Open newsgroup in read-only mode");
1185 cp = _("Open newsgroup");
1186 nntp_buffy (buf, sizeof (buf));
1191 if (Context && Context->path)
1192 m_strcpy(buf, sizeof(buf), Context->path);
1193 if (op != OP_SIDEBAR_OPEN)
1194 buffy_next (buf, sizeof (buf));
1197 if (op == OP_SIDEBAR_OPEN) {
1198 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1200 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1201 if (menu->menu == MENU_PAGER) {
1202 op = OP_DISPLAY_MESSAGE;
1208 CLEARLINE (LINES - 1);
1213 if (option (OPTNEWS)) {
1214 unset_option (OPTNEWS);
1215 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1219 mutt_expand_path (buf, sizeof (buf));
1220 if (mx_get_magic (buf) <= 0) {
1221 mutt_error (_("%s is not a mailbox."), buf);
1224 m_strreplace(&CurrentFolder, buf);
1229 if (Context->compressinfo && Context->realpath)
1230 m_strreplace(&LastFolder, Context->realpath);
1232 m_strreplace(&LastFolder, Context->path);
1233 oldcount = Context ? Context->msgcount : 0;
1235 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1236 if (check == M_NEW_MAIL || check == M_REOPENED)
1237 update_index (menu, Context, check, oldcount, index_hint);
1239 set_option (OPTSEARCHINVALID);
1240 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1248 /* Set CurrentMenu to MENU_MAIN before executing any folder
1249 * hooks so that all the index menu functions are available to
1253 CurrentMenu = MENU_MAIN;
1254 mutt_folder_hook (buf);
1256 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1257 menu->current = ci_first_message ();
1261 sidebar_set_current (buf);
1264 /* buffy_check() must be done with mail-reader mode! */
1265 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1267 && (Context->magic ==
1268 M_NNTP)) ? IndexNewsHelp :
1271 mutt_clear_error ();
1272 buffy_check (0); /* force the buffy check after we have changed
1274 menu->redraw = REDRAW_FULL;
1275 set_option (OPTSEARCHINVALID);
1278 case OP_DISPLAY_MESSAGE:
1279 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1284 * toggle the weeding of headers so that a user can press the key
1285 * again while reading the message.
1287 if (op == OP_DISPLAY_HEADERS)
1288 toggle_option (OPTWEED);
1290 unset_option (OPTNEEDRESORT);
1292 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1293 mutt_uncollapse_thread (Context, CURHDR);
1294 mutt_set_virtual (Context);
1295 if (option (OPTUNCOLLAPSEJUMP))
1296 menu->current = mutt_thread_next_unread (Context, CURHDR);
1299 if (option (OPTPGPAUTODEC) &&
1300 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1301 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1303 if ((op = mutt_display_message (CURHDR)) == -1) {
1304 unset_option (OPTNEEDRESORT);
1308 menu->menu = MENU_PAGER;
1309 menu->oldcurrent = menu->current;
1315 if (menu->menu == MENU_MAIN && attach_msg) {
1320 if ((menu->menu == MENU_MAIN)
1321 && (query_quadoption (OPT_QUIT,
1322 _("Exit Madmutt without saving?")) == M_YES))
1325 mx_fastclose_mailbox (Context);
1337 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1338 /* if we were in the pager, redisplay the message */
1339 if (menu->menu == MENU_PAGER) {
1340 op = OP_DISPLAY_MESSAGE;
1344 menu->redraw = REDRAW_CURRENT;
1347 case OP_MAIN_BREAK_THREAD:
1353 if ((Sort & SORT_MASK) != SORT_THREADS)
1354 mutt_error (_("Threading is not enabled."));
1358 HEADER *oldcur = CURHDR;
1360 mutt_break_thread (CURHDR);
1361 mutt_sort_headers (Context, 1);
1362 menu->current = oldcur->virtual;
1365 Context->changed = 1;
1366 mutt_message _("Thread broken");
1368 if (menu->menu == MENU_PAGER) {
1369 op = OP_DISPLAY_MESSAGE;
1373 menu->redraw |= REDRAW_INDEX;
1377 case OP_MAIN_LINK_THREADS:
1383 if ((Sort & SORT_MASK) != SORT_THREADS)
1384 mutt_error (_("Threading is not enabled."));
1386 else if (!CURHDR->env->message_id)
1387 mutt_error (_("No Message-ID: header available to link thread"));
1389 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1390 mutt_error (_("First, please tag a message to be linked here"));
1393 HEADER *oldcur = CURHDR;
1395 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1397 mutt_sort_headers (Context, 1);
1398 menu->current = oldcur->virtual;
1400 Context->changed = 1;
1401 mutt_message _("Threads linked");
1404 mutt_error (_("No thread linked"));
1407 if (menu->menu == MENU_PAGER) {
1408 op = OP_DISPLAY_MESSAGE;
1412 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1415 case OP_MAIN_NEXT_UNDELETED:
1419 if (menu->current >= Context->vcount - 1) {
1420 if (menu->menu == MENU_MAIN)
1421 mutt_error (_("You are on the last message."));
1425 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1426 menu->current = menu->oldcurrent;
1427 if (menu->menu == MENU_MAIN)
1428 mutt_error (_("No undeleted messages."));
1430 else if (menu->menu == MENU_PAGER) {
1431 op = OP_DISPLAY_MESSAGE;
1435 menu->redraw = REDRAW_MOTION;
1442 if (menu->current >= Context->vcount - 1) {
1443 if (menu->menu == MENU_MAIN)
1444 mutt_error (_("You are on the last message."));
1449 if (menu->menu == MENU_PAGER) {
1450 op = OP_DISPLAY_MESSAGE;
1454 menu->redraw = REDRAW_MOTION;
1457 case OP_MAIN_PREV_UNDELETED:
1461 if (menu->current < 1) {
1462 mutt_error (_("You are on the first message."));
1466 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1467 menu->current = menu->oldcurrent;
1468 if (menu->menu == MENU_MAIN)
1469 mutt_error (_("No undeleted messages."));
1471 else if (menu->menu == MENU_PAGER) {
1472 op = OP_DISPLAY_MESSAGE;
1476 menu->redraw = REDRAW_MOTION;
1483 if (menu->current < 1) {
1484 if (menu->menu == MENU_MAIN)
1485 mutt_error (_("You are on the first message."));
1490 if (menu->menu == MENU_PAGER) {
1491 op = OP_DISPLAY_MESSAGE;
1495 menu->redraw = REDRAW_MOTION;
1498 case OP_DECRYPT_COPY:
1499 case OP_DECRYPT_SAVE:
1500 case OP_COPY_MESSAGE:
1502 case OP_DECODE_COPY:
1503 case OP_DECODE_SAVE:
1506 if (mutt_save_message (tag ? NULL : CURHDR,
1507 (op == OP_DECRYPT_SAVE) ||
1508 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1509 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1510 (op == OP_DECRYPT_SAVE)
1511 || (op == OP_DECRYPT_COPY)
1512 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1519 menu->redraw |= REDRAW_INDEX;
1520 else if (option (OPTRESOLVE)) {
1521 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1522 menu->current = menu->oldcurrent;
1523 menu->redraw |= REDRAW_CURRENT;
1526 menu->redraw |= REDRAW_MOTION_RESYNCH;
1529 menu->redraw |= REDRAW_CURRENT;
1533 case OP_MAIN_NEXT_NEW:
1534 case OP_MAIN_NEXT_UNREAD:
1535 case OP_MAIN_PREV_NEW:
1536 case OP_MAIN_PREV_UNREAD:
1537 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1538 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1541 int first_unread = -1;
1549 for (j = 0; j != Context->vcount; j++) {
1550 #define CURHDRi Context->hdrs[Context->v2r[i]]
1551 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1552 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1554 if (i > Context->vcount - 1) {
1555 mutt_message _("Search wrapped to top.");
1563 mutt_message _("Search wrapped to bottom.");
1565 i = Context->vcount - 1;
1569 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1570 if (UNREAD (CURHDRi) && first_unread == -1)
1572 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1575 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1576 if (first_unread == -1)
1578 if ((!CURHDRi->old) && first_new == -1)
1582 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1585 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1586 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1587 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1592 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1593 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1594 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1596 menu->current = first_new;
1597 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1598 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1599 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1600 && first_unread != -1)
1601 menu->current = first_unread;
1603 if (menu->current == -1) {
1604 menu->current = menu->oldcurrent;
1605 mutt_error ("%s%s.",
1606 (op == OP_MAIN_NEXT_NEW
1608 OP_MAIN_PREV_NEW) ? _("No new messages") :
1609 _("No unread messages"),
1610 Context->pattern ? _(" in this limited view") : "");
1612 else if (menu->menu == MENU_PAGER) {
1613 op = OP_DISPLAY_MESSAGE;
1617 menu->redraw = REDRAW_MOTION;
1620 case OP_FLAG_MESSAGE:
1626 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1629 for (j = 0; j < Context->vcount; j++) {
1630 if (Context->hdrs[Context->v2r[j]]->tagged)
1631 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1632 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1635 menu->redraw |= REDRAW_INDEX;
1638 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1639 if (option (OPTRESOLVE)) {
1640 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1641 menu->current = menu->oldcurrent;
1642 menu->redraw = REDRAW_CURRENT;
1645 menu->redraw = REDRAW_MOTION_RESYNCH;
1648 menu->redraw = REDRAW_CURRENT;
1650 menu->redraw |= REDRAW_STATUS;
1659 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1662 for (j = 0; j < Context->vcount; j++) {
1663 if (Context->hdrs[Context->v2r[j]]->tagged) {
1664 if (Context->hdrs[Context->v2r[j]]->read ||
1665 Context->hdrs[Context->v2r[j]]->old)
1666 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1669 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1673 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1676 if (CURHDR->read || CURHDR->old)
1677 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1679 mutt_set_flag (Context, CURHDR, M_READ, 1);
1681 if (option (OPTRESOLVE)) {
1682 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1683 menu->current = menu->oldcurrent;
1684 menu->redraw = REDRAW_CURRENT;
1687 menu->redraw = REDRAW_MOTION_RESYNCH;
1690 menu->redraw = REDRAW_CURRENT;
1691 menu->redraw |= REDRAW_STATUS;
1695 case OP_TOGGLE_WRITE:
1698 if (mx_toggle_write (Context) == 0)
1699 menu->redraw |= REDRAW_STATUS;
1702 case OP_MAIN_NEXT_THREAD:
1703 case OP_MAIN_NEXT_SUBTHREAD:
1704 case OP_MAIN_PREV_THREAD:
1705 case OP_MAIN_PREV_SUBTHREAD:
1710 case OP_MAIN_NEXT_THREAD:
1711 menu->current = mutt_next_thread (CURHDR);
1714 case OP_MAIN_NEXT_SUBTHREAD:
1715 menu->current = mutt_next_subthread (CURHDR);
1718 case OP_MAIN_PREV_THREAD:
1719 menu->current = mutt_previous_thread (CURHDR);
1722 case OP_MAIN_PREV_SUBTHREAD:
1723 menu->current = mutt_previous_subthread (CURHDR);
1727 if (menu->current < 0) {
1728 menu->current = menu->oldcurrent;
1729 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1730 mutt_error (_("No more threads."));
1733 mutt_error (_("You are on the first thread."));
1735 else if (menu->menu == MENU_PAGER) {
1736 op = OP_DISPLAY_MESSAGE;
1740 menu->redraw = REDRAW_MOTION;
1743 case OP_MAIN_PARENT_MESSAGE:
1748 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1749 menu->current = menu->oldcurrent;
1751 else if (menu->menu == MENU_PAGER) {
1752 op = OP_DISPLAY_MESSAGE;
1756 menu->redraw = REDRAW_MOTION;
1759 case OP_MAIN_SET_FLAG:
1760 case OP_MAIN_CLEAR_FLAG:
1766 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1768 menu->redraw = REDRAW_STATUS;
1770 menu->redraw |= REDRAW_INDEX;
1771 else if (option (OPTRESOLVE)) {
1772 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1773 menu->current = menu->oldcurrent;
1774 menu->redraw |= REDRAW_CURRENT;
1777 menu->redraw |= REDRAW_MOTION_RESYNCH;
1780 menu->redraw |= REDRAW_CURRENT;
1784 case OP_MAIN_COLLAPSE_THREAD:
1788 if ((Sort & SORT_MASK) != SORT_THREADS) {
1789 mutt_error (_("Threading is not enabled."));
1794 if (CURHDR->collapsed) {
1795 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1796 mutt_set_virtual (Context);
1797 if (option (OPTUNCOLLAPSEJUMP))
1798 menu->current = mutt_thread_next_unread (Context, CURHDR);
1800 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1801 menu->current = mutt_collapse_thread (Context, CURHDR);
1802 mutt_set_virtual (Context);
1805 mutt_error (_("Thread contains unread messages."));
1810 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1814 case OP_MAIN_COLLAPSE_ALL:
1818 if ((Sort & SORT_MASK) != SORT_THREADS) {
1819 mutt_error (_("Threading is not enabled."));
1826 THREAD *thread, *top;
1829 if (CURHDR->collapsed)
1830 final = mutt_uncollapse_thread (Context, CURHDR);
1831 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1832 final = mutt_collapse_thread (Context, CURHDR);
1834 final = CURHDR->virtual;
1836 base = Context->hdrs[Context->v2r[final]];
1838 top = Context->tree;
1839 Context->collapsed = !Context->collapsed;
1840 while ((thread = top) != NULL) {
1841 while (!thread->message)
1842 thread = thread->child;
1843 h = thread->message;
1845 if (h->collapsed != Context->collapsed) {
1847 mutt_uncollapse_thread (Context, h);
1848 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1849 mutt_collapse_thread (Context, h);
1854 mutt_set_virtual (Context);
1855 for (j = 0; j < Context->vcount; j++) {
1856 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1862 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1866 /* --------------------------------------------------------------------
1867 * These functions are invoked directly from the internal-pager
1870 case OP_BOUNCE_MESSAGE:
1875 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1878 case OP_CREATE_ALIAS:
1880 mutt_create_alias (Context
1881 && Context->vcount ? CURHDR->env : NULL, NULL);
1882 MAYBE_REDRAW (menu->redraw);
1883 menu->redraw |= REDRAW_CURRENT;
1888 mutt_query_menu (NULL, 0);
1889 MAYBE_REDRAW (menu->redraw);
1892 case OP_PURGE_MESSAGE:
1899 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1902 mutt_tag_set_flag (M_DELETE, 1);
1903 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1904 if (option (OPTDELETEUNTAG))
1905 mutt_tag_set_flag (M_TAG, 0);
1906 menu->redraw = REDRAW_INDEX;
1909 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1910 mutt_set_flag (Context, CURHDR, M_PURGED,
1911 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1912 if (option (OPTDELETEUNTAG))
1913 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1914 if (option (OPTRESOLVE)) {
1915 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1916 menu->current = menu->oldcurrent;
1917 menu->redraw = REDRAW_CURRENT;
1919 else if (menu->menu == MENU_PAGER) {
1920 op = OP_DISPLAY_MESSAGE;
1924 menu->redraw |= REDRAW_MOTION_RESYNCH;
1927 menu->redraw = REDRAW_CURRENT;
1929 menu->redraw |= REDRAW_STATUS;
1932 case OP_DELETE_THREAD:
1933 case OP_DELETE_SUBTHREAD:
1939 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1941 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1942 op == OP_DELETE_THREAD ? 0 : 1);
1945 if (option (OPTDELETEUNTAG))
1946 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1947 op == OP_DELETE_THREAD ? 0 : 1);
1948 if (option (OPTRESOLVE))
1949 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1950 menu->current = menu->oldcurrent;
1951 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1957 if (Context && Context->magic == M_NNTP) {
1958 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1959 ((NNTP_DATA *) Context->data)->group))
1960 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1965 case OP_DISPLAY_ADDRESS:
1969 mutt_display_address (CURHDR->env);
1972 case OP_ENTER_COMMAND:
1974 CurrentMenu = MENU_MAIN;
1975 mutt_enter_command ();
1976 mutt_check_rescore (Context);
1977 if (option (OPTFORCEREDRAWINDEX))
1978 menu->redraw = REDRAW_FULL;
1979 unset_option (OPTFORCEREDRAWINDEX);
1980 unset_option (OPTFORCEREDRAWPAGER);
1983 case OP_EDIT_MESSAGE:
1990 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1992 if (option (OPTPGPAUTODEC)
1993 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1994 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1995 mutt_edit_message (Context, tag ? NULL : CURHDR);
1996 menu->redraw = REDRAW_FULL;
2000 case OP_FORWARD_MESSAGE:
2006 if (option (OPTPGPAUTODEC) &&
2007 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2008 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2009 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2010 menu->redraw = REDRAW_FULL;
2014 case OP_FORGET_PASSPHRASE:
2015 crypt_forget_passphrase ();
2018 case OP_GROUP_REPLY:
2024 if (option (OPTPGPAUTODEC) &&
2025 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2026 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2028 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2029 tag ? NULL : CURHDR);
2030 menu->redraw = REDRAW_FULL;
2039 if (option (OPTPGPAUTODEC) &&
2040 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2041 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2043 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2044 tag ? NULL : CURHDR);
2045 menu->redraw = REDRAW_FULL;
2051 ci_send_message (0, NULL, NULL, Context, NULL);
2052 menu->redraw = REDRAW_FULL;
2057 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2058 menu->redraw = REDRAW_FULL;
2062 case OP_EXTRACT_KEYS:
2065 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2066 menu->redraw = REDRAW_FULL;
2070 case OP_CHECK_TRADITIONAL:
2073 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2074 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2076 if (menu->menu == MENU_PAGER) {
2077 op = OP_DISPLAY_MESSAGE;
2086 mutt_pipe_message (tag ? NULL : CURHDR);
2087 /* in an IMAP folder index with imap_peek=no, piping could change
2088 * * new or old messages status to read. Redraw what's needed.
2090 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2091 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2093 MAYBE_REDRAW (menu->redraw);
2100 mutt_print_message (tag ? NULL : CURHDR);
2101 /* in an IMAP folder index with imap_peek=no, piping could change
2102 * * new or old messages status to read. Redraw what's needed.
2104 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2105 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2109 case OP_MAIN_READ_THREAD:
2110 case OP_MAIN_READ_SUBTHREAD:
2116 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2118 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2119 op == OP_MAIN_READ_THREAD ? 0 : 1);
2122 if (option (OPTRESOLVE)) {
2123 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2124 mutt_next_thread (CURHDR) :
2125 mutt_next_subthread (CURHDR))) == -1)
2126 menu->current = menu->oldcurrent;
2128 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2132 case OP_RECALL_MESSAGE:
2135 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2136 menu->redraw = REDRAW_FULL;
2146 for (j = 0; j < Context->vcount; j++) {
2147 if (Context->hdrs[Context->v2r[j]]->tagged)
2148 mutt_resend_message (NULL, Context,
2149 Context->hdrs[Context->v2r[j]]);
2153 mutt_resend_message (NULL, Context, CURHDR);
2155 menu->redraw = REDRAW_FULL;
2161 case OP_FORWARD_TO_GROUP:
2164 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2165 Context && Context->msgcount == 0) {
2166 mutt_error (_("There are no messages."));
2169 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2170 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2171 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2172 _("Reply by mail as poster prefers?")) !=
2174 if (Context && Context->magic == M_NNTP
2175 && !((NNTP_DATA *) Context->data)->allowed
2176 && query_quadoption (OPT_TOMODERATED,
2178 ("Posting to this group not allowed, may be moderated. Continue?"))
2182 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2185 if (op == OP_FOLLOWUP)
2186 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2187 tag ? NULL : CURHDR);
2189 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2190 tag ? NULL : CURHDR);
2192 menu->redraw = REDRAW_FULL;
2203 if (option (OPTPGPAUTODEC) &&
2204 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2205 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2207 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2208 menu->redraw = REDRAW_FULL;
2211 case OP_SHELL_ESCAPE:
2213 mutt_shell_escape ();
2214 MAYBE_REDRAW (menu->redraw);
2218 case OP_TAG_SUBTHREAD:
2222 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2223 op == OP_TAG_THREAD ? 0 : 1);
2226 if (option (OPTRESOLVE)) {
2227 menu->current = mutt_next_thread (CURHDR);
2229 if (menu->current == -1)
2230 menu->current = menu->oldcurrent;
2232 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2242 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2245 mutt_tag_set_flag (M_DELETE, 0);
2246 mutt_tag_set_flag (M_PURGED, 0);
2247 menu->redraw = REDRAW_INDEX;
2250 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2251 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2252 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2254 menu->redraw = REDRAW_MOTION_RESYNCH;
2257 menu->redraw = REDRAW_CURRENT;
2259 menu->redraw |= REDRAW_STATUS;
2262 case OP_UNDELETE_THREAD:
2263 case OP_UNDELETE_SUBTHREAD:
2269 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2271 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2272 op == OP_UNDELETE_THREAD ? 0 : 1)
2273 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2274 op == OP_UNDELETE_THREAD ? 0 : 1);
2277 if (option (OPTRESOLVE)) {
2278 if (op == OP_UNDELETE_THREAD)
2279 menu->current = mutt_next_thread (CURHDR);
2281 menu->current = mutt_next_subthread (CURHDR);
2283 if (menu->current == -1)
2284 menu->current = menu->oldcurrent;
2286 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2295 if (option (OPTFORCEBUFFYCHECK))
2298 menu->redraw = REDRAW_FULL;
2301 case OP_VIEW_ATTACHMENTS:
2304 mutt_view_attachments (CURHDR);
2305 if (CURHDR->attach_del)
2306 Context->changed = 1;
2307 menu->redraw = REDRAW_FULL;
2317 case OP_REBUILD_CACHE:
2318 mx_rebuild_cache ();
2321 case OP_SIDEBAR_SCROLL_UP:
2322 case OP_SIDEBAR_SCROLL_DOWN:
2323 case OP_SIDEBAR_NEXT:
2324 case OP_SIDEBAR_PREV:
2325 case OP_SIDEBAR_NEXT_NEW:
2326 case OP_SIDEBAR_PREV_NEW:
2327 sidebar_scroll (op, menu->menu);
2330 if (menu->menu == MENU_MAIN)
2331 km_error_key (MENU_MAIN);
2334 if (menu->menu == MENU_PAGER) {
2335 menu->menu = MENU_MAIN;
2336 menu->redraw = REDRAW_FULL;
2338 set_option (OPTWEED); /* turn header weeding back on. */
2347 /* Close all open IMAP connections */
2350 /* Close all open NNTP connections */
2358 mutt_menuDestroy (&menu);
2362 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2369 for (color = ColorIndexList; color; color = color->next)
2370 if (mutt_pattern_exec
2371 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2372 curhdr->pair = color->pair;
2375 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];