2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * Parts were written/modified by:
6 * Nico Golde <nico@ngolde.de>
8 * This file is part of mutt-ng, see http://www.muttng.org/.
9 * It's licensed under the GNU General Public License,
10 * please see the file GPL in the top level source directory.
17 #include <lib-lib/mem.h>
18 #include <lib-lib/str.h>
19 #include <lib-lib/macros.h>
20 #include <lib-lib/mapping.h>
25 #include "mutt_curses.h"
27 #include "mutt_menu.h"
29 #include "recvattach.h"
37 #include "imap_private.h"
40 #include "mutt_crypt.h"
47 #include "mutt_sasl.h"
50 #include "lib/debug.h"
60 static const char *No_mailbox_is_open = N_("No mailbox is open.");
61 static const char *There_are_no_messages = N_("There are no messages.");
62 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
63 static const char *Function_not_permitted_in_attach_message_mode =
64 N_("Function not permitted in attach-message mode.");
65 static const char *No_visible = N_("No visible messages.");
67 #define CHECK_IN_MAILBOX if (!Context) \
70 mutt_error (_(No_mailbox_is_open)); \
74 #define CHECK_MSGCOUNT if (!Context) \
77 mutt_error(_(No_mailbox_is_open)); \
80 else if (!Context->msgcount) \
83 mutt_error(_(There_are_no_messages)); \
87 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
90 mutt_error(_(No_visible)); \
95 #define CHECK_READONLY if (Context->readonly) \
98 mutt_error(_(Mailbox_is_read_only)); \
102 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
105 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
109 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
110 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
111 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
112 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
114 extern size_t UngetCount;
116 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
119 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
120 int edgemsgno, reverse = Sort & SORT_REVERSE;
121 HEADER *h = Context->hdrs[Context->v2r[num]];
124 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
125 flag |= M_FORMAT_TREE; /* display the thread tree */
126 if (h->display_subject)
127 flag |= M_FORMAT_FORCESUBJ;
130 if (menu->top + menu->pagelen > menu->max)
131 edgemsgno = Context->v2r[menu->max - 1];
133 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
136 edgemsgno = Context->v2r[menu->top];
138 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
142 /* if no ancestor is visible on current screen, provisionally force
144 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
146 flag |= M_FORMAT_FORCESUBJ;
149 else if (tmp->message->virtual >= 0)
152 if (flag & M_FORMAT_FORCESUBJ) {
153 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
157 /* ...but if a previous sibling is available, don't force it */
158 if (reverse ? tmp->message->msgno >
159 edgemsgno : tmp->message->msgno < edgemsgno)
161 else if (tmp->message->virtual >= 0) {
162 flag &= ~M_FORMAT_FORCESUBJ;
170 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
173 int index_color (int index_no)
175 HEADER *h = Context->hdrs[Context->v2r[index_no]];
180 mutt_set_header_color (Context, h);
184 static int ci_next_undeleted (int msgno)
188 for (i = msgno + 1; i < Context->vcount; i++)
189 if (!Context->hdrs[Context->v2r[i]]->deleted)
194 static int ci_previous_undeleted (int msgno)
198 for (i = msgno - 1; i >= 0; i--)
199 if (!Context->hdrs[Context->v2r[i]]->deleted)
204 /* Return the index of the first new message, or failing that, the first
207 static int ci_first_message (void)
211 if (Context && Context->msgcount) {
212 for (i = 0; i < Context->vcount; i++) {
213 if (!Context->hdrs[Context->v2r[i]]->read &&
214 !Context->hdrs[Context->v2r[i]]->deleted) {
215 if (!Context->hdrs[Context->v2r[i]]->old)
224 /* If Sort is reverse and not threaded, the latest message is first.
225 * If Sort is threaded, the latest message is first iff exactly one
226 * of Sort and SortAux are reverse.
228 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
229 ((Sort & SORT_MASK) == SORT_THREADS &&
230 ((Sort ^ SortAux) & SORT_REVERSE)))
233 return (Context->vcount ? Context->vcount - 1 : 0);
238 /* This should be in mx.c, but it only gets used here. */
239 static int mx_toggle_write (CONTEXT * ctx)
245 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
250 if (ctx->dontwrite) {
252 mutt_message (_("Changes to folder will be written on folder exit."));
256 mutt_message (_("Changes to folder will not be written."));
262 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
263 int oldcount, int index_hint)
265 /* store pointers to the newly added messages */
266 HEADER **save_new = NULL;
269 /* take note of the current message */
271 if (menu->current < Context->vcount)
272 menu->oldcurrent = index_hint;
274 oldcount = 0; /* invalid message number! */
277 /* We are in a limited view. Check if the new message(s) satisfy
278 * the limit criteria. If they do, set their virtual msgno so that
279 * they will be visible in the limited view */
280 if (Context->pattern) {
281 #define THIS_BODY Context->hdrs[j]->content
282 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
283 if (mutt_pattern_exec
284 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
286 Context->hdrs[j]->virtual = Context->vcount;
287 Context->v2r[Context->vcount] = j;
288 Context->hdrs[j]->limited = 1;
291 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
297 /* save the list of new messages */
298 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
299 save_new = p_new(HEADER*, Context->msgcount - oldcount);
300 for (j = oldcount; j < Context->msgcount; j++)
301 save_new[j - oldcount] = Context->hdrs[j];
304 /* if the mailbox was reopened, need to rethread from scratch */
305 mutt_sort_headers (Context, (check == M_REOPENED));
307 /* uncollapse threads with new mail */
308 if ((Sort & SORT_MASK) == SORT_THREADS) {
309 if (check == M_REOPENED) {
312 Context->collapsed = 0;
314 for (h = Context->tree; h; h = h->next) {
315 for (c = h; !c->message; c = c->child);
316 mutt_uncollapse_thread (Context, c->message);
318 mutt_set_virtual (Context);
321 for (j = 0; j < Context->msgcount - oldcount; j++) {
324 for (k = 0; k < Context->msgcount; k++) {
325 HEADER *h = Context->hdrs[k];
327 if (h == save_new[j] && (!Context->pattern || h->limited))
328 mutt_uncollapse_thread (Context, h);
332 mutt_set_virtual (Context);
338 /* restore the current message to the message it was pointing to */
339 for (j = 0; j < Context->vcount; j++) {
340 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
347 if (menu->current < 0)
348 menu->current = ci_first_message ();
351 static void resort_index (MUTTMENU * menu)
354 HEADER *current = CURHDR;
357 mutt_sort_headers (Context, 0);
358 /* Restore the current message */
360 for (i = 0; i < Context->vcount; i++) {
361 if (Context->hdrs[Context->v2r[i]] == current) {
367 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
368 menu->current = mutt_parent_message (Context, current);
370 if (menu->current < 0)
371 menu->current = ci_first_message ();
373 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
376 struct mapping_t IndexHelp[] = {
377 {N_("Quit"), OP_QUIT},
378 {N_("Del"), OP_DELETE},
379 {N_("Undel"), OP_UNDELETE},
380 {N_("Save"), OP_SAVE},
381 {N_("Mail"), OP_MAIL},
382 {N_("Reply"), OP_REPLY},
383 {N_("Group"), OP_GROUP_REPLY},
384 {N_("Help"), OP_HELP},
389 struct mapping_t IndexNewsHelp[] = {
390 {N_("Quit"), OP_QUIT},
391 {N_("Del"), OP_DELETE},
392 {N_("Undel"), OP_UNDELETE},
393 {N_("Save"), OP_SAVE},
394 {N_("Post"), OP_POST},
395 {N_("Followup"), OP_FOLLOWUP},
396 {N_("Catchup"), OP_CATCHUP},
397 {N_("Help"), OP_HELP},
402 /* This function handles the message index window as well as commands returned
403 * from the pager (MENU_PAGER).
405 int mutt_index_menu (void)
407 char buf[LONG_STRING], helpstr[SHORT_STRING];
410 int done = 0; /* controls when to exit the "event" loop */
412 int tag = 0; /* has the tag-prefix command been pressed? */
417 char *cp; /* temporary variable. */
418 int index_hint; /* used to restore cursor position */
419 int do_buffy_notify = 1;
420 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
421 int attach_msg = option (OPTATTACHMSG);
423 menu = mutt_new_menu ();
424 menu->menu = MENU_MAIN;
426 menu->pagelen = LINES - 3;
427 menu->make_entry = (void *) index_make_entry;
428 menu->color = index_color;
429 menu->current = ci_first_message ();
430 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
433 && (Context->magic ==
434 M_NNTP)) ? IndexNewsHelp :
439 buffy_check (1); /* force the buffy check after we enter the folder */
440 /* record folder we open to place sidebar indicator properly */
441 if (Context && Context->path)
442 sidebar_set_current (Context->path);
446 tag = 0; /* clear the tag-prefix */
448 menu->max = Context ? Context->vcount : 0;
449 oldcount = Context ? Context->msgcount : 0;
451 /* check if we need to resort the index because just about
452 * any 'op' below could do mutt_enter_command(), either here or
453 * from any new menu launched, and change $sort/$sort_aux
455 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
458 if (option (OPTREDRAWTREE) && Context && Context->msgcount
459 && (Sort & SORT_MASK) == SORT_THREADS) {
460 mutt_draw_tree (Context);
461 menu->redraw |= REDRAW_STATUS;
462 unset_option (OPTREDRAWTREE);
465 if (Context && !attach_msg) {
468 /* check for new mail in the mailbox. If nonzero, then something has
469 * changed about the file (either we got new mail or the file was
470 * modified underneath us.)
474 imap_allow_reopen (Context);
477 index_hint = (Context->vcount && menu->current >= 0
478 && menu->current < Context->vcount) ? CURHDR->index : 0;
480 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
481 if (!Context->path) {
482 /* fatal error occurred */
484 menu->redraw = REDRAW_FULL;
486 set_option (OPTSEARCHINVALID);
488 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
489 update_index (menu, Context, check, oldcount, index_hint);
491 /* notify the user of new mail */
492 if (check == M_REOPENED)
494 ("Mailbox was externally modified. Flags may be wrong."));
495 else if (check == M_NEW_MAIL) {
496 /* on new mail: redraw sidebar */
497 sidebar_draw (CurrentMenu);
498 mutt_message (_("New mail in this mailbox."));
500 if (option (OPTBEEPNEW))
503 else if (check == M_FLAGS)
504 mutt_message (_("Mailbox was externally modified."));
506 /* avoid the message being overwritten by buffy */
509 menu->redraw = REDRAW_FULL;
510 menu->max = Context->vcount;
512 set_option (OPTSEARCHINVALID);
518 imap_disallow_reopen (Context);
522 /* check for new mail in the incoming folders */
524 if ((newcount = buffy_check (0)) != oldcount) {
525 menu->redraw |= REDRAW_STATUS;
526 menu->redraw |= REDRAW_SIDEBAR;
528 if (do_buffy_notify) {
529 if (buffy_notify () && option (OPTBEEPNEW))
538 if (menu->redraw & REDRAW_SIDEBAR)
539 sidebar_draw (menu->menu);
540 if (menu->redraw & REDRAW_FULL) {
541 menu_redraw_full (menu);
542 sidebar_draw (menu->menu);
546 if (menu->menu == MENU_MAIN) {
547 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
548 menu_check_recenter (menu);
550 if (menu->redraw & REDRAW_INDEX) {
551 menu_redraw_index (menu);
552 menu->redraw |= REDRAW_STATUS;
554 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
555 menu_redraw_motion (menu);
556 else if (menu->redraw & REDRAW_CURRENT)
557 menu_redraw_current (menu);
560 if (menu->redraw & REDRAW_STATUS) {
561 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
562 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
563 sidebar_draw_frames();
564 SETCOLOR (MT_COLOR_STATUS);
565 BKGDSET (MT_COLOR_STATUS);
566 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
567 mutt_paddstr (COLS-SW, buf);
568 SETCOLOR (MT_COLOR_NORMAL);
569 BKGDSET (MT_COLOR_NORMAL);
570 sidebar_set_buffystats (Context);
571 menu->redraw &= ~REDRAW_STATUS;
572 if (option (OPTXTERMSETTITLES)) {
573 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
574 mutt_xterm_set_title (buf);
575 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
576 mutt_xterm_set_icon (buf);
581 if (menu->current < menu->max)
582 menu->oldcurrent = menu->current;
584 menu->oldcurrent = -1;
586 if (option (OPTARROWCURSOR))
587 move (menu->current - menu->top + menu->offset, 2);
588 else if (option (OPTBRAILLEFRIENDLY))
589 move (menu->current - menu->top + menu->offset, 0);
591 move (menu->current - menu->top + menu->offset, COLS - 1);
594 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
597 mutt_resize_screen ();
598 menu->redraw = REDRAW_FULL;
599 menu->menu = MENU_MAIN;
601 menu->top = 0; /* so we scroll the right amount */
603 * force a real complete redraw. clrtobot() doesn't seem to be able
604 * to handle every case without this.
606 clearok (stdscr, TRUE);
611 op = km_dokey (MENU_MAIN);
613 debug_print (4, ("Got op %d\n", op));
616 continue; /* either user abort or timeout */
620 /* special handling for the tag-prefix function */
621 if (op == OP_TAG_PREFIX) {
623 mutt_error (_("No mailbox is open."));
628 if (!Context->tagged) {
629 mutt_error (_("No tagged messages."));
635 /* give visual indication that the next command is a tag- command */
636 mvaddstr (LINES - 1, 0, "tag-");
639 /* get the real command */
640 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
641 /* abort tag sequence */
642 CLEARLINE (LINES - 1);
646 else if (option (OPTAUTOTAG) && Context && Context->tagged)
649 if (op == OP_TAG_PREFIX_COND) {
651 mutt_error (_("No mailbox is open."));
656 if (!Context->tagged) {
659 while (UngetCount > 0) {
661 if (tmp.op == OP_END_COND)
664 mutt_message (_("Nothing to do."));
670 /* give visual indication that the next command is a tag- command */
671 mvaddstr (LINES - 1, 0, "tag-");
674 /* get the real command */
675 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
676 /* abort tag sequence */
677 CLEARLINE (LINES - 1);
685 if (menu->current < menu->max)
686 menu->oldcurrent = menu->current;
688 menu->oldcurrent = -1;
690 mutt_curs_set (1); /* fallback from the pager */
694 unset_option (OPTNEWS); /* for any case */
699 /* ----------------------------------------------------------------------
704 menu_bottom_page (menu);
707 menu_first_entry (menu);
710 menu_middle_page (menu);
716 menu_half_down (menu);
719 menu_next_line (menu);
722 menu_prev_line (menu);
725 menu_next_page (menu);
728 menu_prev_page (menu);
731 menu_last_entry (menu);
734 menu_top_page (menu);
737 menu_current_top (menu);
739 case OP_CURRENT_MIDDLE:
740 menu_current_middle (menu);
742 case OP_CURRENT_BOTTOM:
743 menu_current_bottom (menu);
750 if (Context->magic == M_NNTP) {
753 if (op == OP_GET_MESSAGE) {
755 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
760 LIST *ref = CURHDR->env->references;
763 mutt_error (_("Article has no parent reference!"));
767 m_strcpy(buf, sizeof(buf), ref->data);
769 if (!Context->id_hash)
770 Context->id_hash = mutt_make_id_hash (Context);
771 if ((h = hash_find (Context->id_hash, buf))) {
772 if (h->virtual != -1) {
773 menu->current = h->virtual;
774 menu->redraw = REDRAW_MOTION_RESYNCH;
776 else if (h->collapsed) {
777 mutt_uncollapse_thread (Context, h);
778 mutt_set_virtual (Context);
779 menu->current = h->virtual;
780 menu->redraw = REDRAW_MOTION_RESYNCH;
783 mutt_error (_("Message not visible in limited view."));
786 if (nntp_check_msgid (Context, buf) == 0) {
787 h = Context->hdrs[Context->msgcount - 1];
788 mutt_sort_headers (Context, 0);
789 menu->current = h->virtual;
790 menu->redraw = REDRAW_FULL;
793 mutt_error (_("Article %s not found on server"), buf);
798 case OP_GET_CHILDREN:
799 case OP_RECONSTRUCT_THREAD:
801 if (Context->magic == M_NNTP) {
803 int old = CURHDR->index, i;
805 if (!CURHDR->env->message_id) {
806 mutt_error (_("No Message-ID. Unable to perform operation"));
811 if (!Context->id_hash)
812 Context->id_hash = mutt_make_id_hash (Context);
813 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
815 if (op == OP_RECONSTRUCT_THREAD) {
816 LIST *ref = CURHDR->env->references;
819 nntp_check_msgid (Context, ref->data);
820 /* the last msgid in References is the root message */
822 m_strcpy(buf, sizeof(buf), ref->data);
826 mutt_message (_("Check for children of message..."));
828 if (nntp_check_children (Context, buf) == 0) {
829 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
830 h = hash_find (Context->id_hash, buf);
831 /* if the root message was retrieved, move to it */
833 menu->current = h->virtual;
834 else /* try to restore old position */
835 for (i = 0; i < Context->msgcount; i++)
836 if (Context->hdrs[i]->index == old) {
837 menu->current = Context->hdrs[i]->virtual;
838 /* As an added courtesy, recenter the menu
839 * with the current entry at the middle of the screen */
840 menu_check_recenter (menu);
841 menu_current_middle (menu);
844 menu->redraw = REDRAW_FULL;
854 if (isdigit (LastKey))
855 mutt_ungetch (LastKey, 0);
857 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
861 if (!isdigit ((unsigned char) buf[0])) {
862 mutt_error (_("Argument must be a message number."));
868 if (i > 0 && i <= Context->msgcount) {
869 for (j = i - 1; j < Context->msgcount; j++) {
870 if (Context->hdrs[j]->virtual != -1)
873 if (j >= Context->msgcount) {
874 for (j = i - 2; j >= 0; j--) {
875 if (Context->hdrs[j]->virtual != -1)
881 menu->current = Context->hdrs[j]->virtual;
882 if (menu->menu == MENU_PAGER) {
883 op = OP_DISPLAY_MESSAGE;
887 menu->redraw = REDRAW_MOTION;
890 mutt_error (_("That message is not visible."));
893 mutt_error (_("Invalid message number."));
897 /* --------------------------------------------------------------------
898 * `index' specific commands
901 case OP_MAIN_DELETE_PATTERN:
907 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
910 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
911 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
914 case OP_MAIN_FETCH_MAIL:
918 menu->redraw = REDRAW_FULL;
923 mutt_help (MENU_MAIN);
924 menu->redraw = REDRAW_FULL;
927 case OP_MAIN_SHOW_LIMIT:
929 if (!Context->pattern)
930 mutt_message (_("No limit pattern is in effect."));
935 /* i18n: ask for a limit to apply */
936 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
937 mutt_message ("%s", buffer);
945 menu->oldcurrent = (Context->vcount && menu->current >= 0
947 Context->vcount) ? CURHDR->index : -1;
948 if (op == OP_TOGGLE_READ) {
949 char buffer[LONG_STRING];
951 if (!Context->pattern
952 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
953 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
954 Context->pattern ? Context->pattern : ".*");
955 set_option (OPTHIDEREAD);
958 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
959 if (!*buf || strncmp (buf, ".*", 2) == 0)
960 snprintf (buf, sizeof (buf), "~A");
961 unset_option (OPTHIDEREAD);
963 p_delete(&Context->pattern);
964 Context->pattern = m_strdup(buf);
966 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
967 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
969 if (menu->oldcurrent >= 0) {
970 /* try to find what used to be the current message */
972 for (i = 0; i < Context->vcount; i++)
973 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
977 if (menu->current < 0)
982 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
983 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
984 mutt_draw_tree (Context);
985 menu->redraw = REDRAW_FULL;
987 if (Context->pattern)
988 mutt_message _("To view all messages, limit to \"all\".");
999 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1002 oldcount = Context ? Context->msgcount : 0;
1005 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1008 if (check == M_NEW_MAIL || check == M_REOPENED)
1009 update_index (menu, Context, check, oldcount, index_hint);
1011 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1012 set_option (OPTSEARCHINVALID);
1019 clearok (stdscr, TRUE);
1020 menu->redraw = REDRAW_FULL;
1024 case OP_SEARCH_REVERSE:
1025 case OP_SEARCH_NEXT:
1026 case OP_SEARCH_OPPOSITE:
1030 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1031 menu->current = menu->oldcurrent;
1033 menu->redraw = REDRAW_MOTION;
1037 case OP_SORT_REVERSE:
1039 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1040 if (Context && Context->msgcount) {
1041 resort_index (menu);
1042 set_option (OPTSEARCHINVALID);
1051 if (tag && !option (OPTAUTOTAG)) {
1052 for (j = 0; j < Context->vcount; j++)
1053 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1054 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1057 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1058 Context->last_tag = CURHDR->tagged ? CURHDR :
1059 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1060 ? NULL : Context->last_tag);
1061 menu->redraw = REDRAW_STATUS;
1062 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1064 menu->redraw |= REDRAW_MOTION_RESYNCH;
1067 menu->redraw |= REDRAW_CURRENT;
1071 case OP_MAIN_TAG_PATTERN:
1075 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1076 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1079 case OP_MAIN_UNDELETE_PATTERN:
1085 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1087 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1089 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1092 case OP_MAIN_UNTAG_PATTERN:
1096 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1097 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1100 /* --------------------------------------------------------------------
1101 * The following operations can be performed inside of the pager.
1105 case OP_MAIN_IMAP_FETCH:
1106 if (Context->magic == M_IMAP)
1107 imap_check_mailbox (Context, &index_hint, 1);
1111 case OP_MAIN_SYNC_FOLDER:
1113 if (Context && !Context->msgcount)
1120 int oldvcount = Context->vcount;
1121 oldcount = Context->msgcount;
1125 /* calculate the number of messages _above_ the cursor,
1126 * so we can keep the cursor on the current message
1128 for (j = 0; j <= menu->current; j++) {
1129 if (Context->hdrs[Context->v2r[j]]->deleted)
1133 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1134 if (Context->vcount != oldvcount)
1135 menu->current -= dcount;
1136 set_option (OPTSEARCHINVALID);
1138 else if (check == M_NEW_MAIL || check == M_REOPENED)
1139 update_index (menu, Context, check, oldcount, index_hint);
1142 * do a sanity check even if mx_sync_mailbox failed.
1145 if (menu->current < 0 || menu->current >= Context->vcount)
1146 menu->current = ci_first_message ();
1149 /* check for a fatal error, or all messages deleted */
1153 /* if we were in the pager, redisplay the message */
1154 if (menu->menu == MENU_PAGER) {
1155 op = OP_DISPLAY_MESSAGE;
1159 menu->redraw = REDRAW_FULL;
1162 case OP_SIDEBAR_OPEN:
1163 case OP_MAIN_CHANGE_FOLDER:
1164 case OP_MAIN_CHANGE_FOLDER_READONLY:
1166 case OP_MAIN_CHANGE_GROUP:
1167 case OP_MAIN_CHANGE_GROUP_READONLY:
1169 if (attach_msg || option (OPTREADONLY) ||
1171 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1173 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1179 cp = _("Open mailbox in read-only mode");
1181 cp = _("Open mailbox");
1185 unset_option (OPTNEWS);
1186 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1187 set_option (OPTNEWS);
1188 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1191 cp = _("Open newsgroup in read-only mode");
1193 cp = _("Open newsgroup");
1194 nntp_buffy (buf, sizeof (buf));
1199 if (Context && Context->path)
1200 m_strcpy(buf, sizeof(buf), Context->path);
1201 if (op != OP_SIDEBAR_OPEN)
1202 buffy_next (buf, sizeof (buf));
1205 if (op == OP_SIDEBAR_OPEN) {
1206 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1208 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1209 if (menu->menu == MENU_PAGER) {
1210 op = OP_DISPLAY_MESSAGE;
1216 CLEARLINE (LINES - 1);
1221 if (option (OPTNEWS)) {
1222 unset_option (OPTNEWS);
1223 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1227 mutt_expand_path (buf, sizeof (buf));
1228 if (mx_get_magic (buf) <= 0) {
1229 mutt_error (_("%s is not a mailbox."), buf);
1232 m_strreplace(&CurrentFolder, buf);
1237 if (Context->compressinfo && Context->realpath)
1238 m_strreplace(&LastFolder, Context->realpath);
1240 m_strreplace(&LastFolder, Context->path);
1241 oldcount = Context ? Context->msgcount : 0;
1243 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1244 if (check == M_NEW_MAIL || check == M_REOPENED)
1245 update_index (menu, Context, check, oldcount, index_hint);
1247 set_option (OPTSEARCHINVALID);
1248 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1256 /* Set CurrentMenu to MENU_MAIN before executing any folder
1257 * hooks so that all the index menu functions are available to
1261 CurrentMenu = MENU_MAIN;
1262 mutt_folder_hook (buf);
1264 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1265 menu->current = ci_first_message ();
1269 sidebar_set_current (buf);
1272 /* buffy_check() must be done with mail-reader mode! */
1273 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1275 && (Context->magic ==
1276 M_NNTP)) ? IndexNewsHelp :
1279 mutt_clear_error ();
1280 buffy_check (1); /* force the buffy check after we have changed
1282 menu->redraw = REDRAW_FULL;
1283 set_option (OPTSEARCHINVALID);
1286 case OP_DISPLAY_MESSAGE:
1287 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1292 * toggle the weeding of headers so that a user can press the key
1293 * again while reading the message.
1295 if (op == OP_DISPLAY_HEADERS)
1296 toggle_option (OPTWEED);
1298 unset_option (OPTNEEDRESORT);
1300 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1301 mutt_uncollapse_thread (Context, CURHDR);
1302 mutt_set_virtual (Context);
1303 if (option (OPTUNCOLLAPSEJUMP))
1304 menu->current = mutt_thread_next_unread (Context, CURHDR);
1307 if (option (OPTPGPAUTODEC) &&
1308 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1309 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1311 if ((op = mutt_display_message (CURHDR)) == -1) {
1312 unset_option (OPTNEEDRESORT);
1316 menu->menu = MENU_PAGER;
1317 menu->oldcurrent = menu->current;
1323 if (menu->menu == MENU_MAIN && attach_msg) {
1328 if ((menu->menu == MENU_MAIN)
1329 && (query_quadoption (OPT_QUIT,
1330 _("Exit Mutt-ng without saving?")) == M_YES))
1333 mx_fastclose_mailbox (Context);
1345 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1346 /* if we were in the pager, redisplay the message */
1347 if (menu->menu == MENU_PAGER) {
1348 op = OP_DISPLAY_MESSAGE;
1352 menu->redraw = REDRAW_CURRENT;
1355 case OP_MAIN_BREAK_THREAD:
1361 if ((Sort & SORT_MASK) != SORT_THREADS)
1362 mutt_error (_("Threading is not enabled."));
1366 HEADER *oldcur = CURHDR;
1368 mutt_break_thread (CURHDR);
1369 mutt_sort_headers (Context, 1);
1370 menu->current = oldcur->virtual;
1373 Context->changed = 1;
1374 mutt_message _("Thread broken");
1376 if (menu->menu == MENU_PAGER) {
1377 op = OP_DISPLAY_MESSAGE;
1381 menu->redraw |= REDRAW_INDEX;
1385 case OP_MAIN_LINK_THREADS:
1391 if ((Sort & SORT_MASK) != SORT_THREADS)
1392 mutt_error (_("Threading is not enabled."));
1394 else if (!CURHDR->env->message_id)
1395 mutt_error (_("No Message-ID: header available to link thread"));
1397 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1398 mutt_error (_("First, please tag a message to be linked here"));
1401 HEADER *oldcur = CURHDR;
1403 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1405 mutt_sort_headers (Context, 1);
1406 menu->current = oldcur->virtual;
1408 Context->changed = 1;
1409 mutt_message _("Threads linked");
1412 mutt_error (_("No thread linked"));
1415 if (menu->menu == MENU_PAGER) {
1416 op = OP_DISPLAY_MESSAGE;
1420 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1423 case OP_MAIN_NEXT_UNDELETED:
1427 if (menu->current >= Context->vcount - 1) {
1428 if (menu->menu == MENU_MAIN)
1429 mutt_error (_("You are on the last message."));
1433 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1434 menu->current = menu->oldcurrent;
1435 if (menu->menu == MENU_MAIN)
1436 mutt_error (_("No undeleted messages."));
1438 else if (menu->menu == MENU_PAGER) {
1439 op = OP_DISPLAY_MESSAGE;
1443 menu->redraw = REDRAW_MOTION;
1450 if (menu->current >= Context->vcount - 1) {
1451 if (menu->menu == MENU_MAIN)
1452 mutt_error (_("You are on the last message."));
1457 if (menu->menu == MENU_PAGER) {
1458 op = OP_DISPLAY_MESSAGE;
1462 menu->redraw = REDRAW_MOTION;
1465 case OP_MAIN_PREV_UNDELETED:
1469 if (menu->current < 1) {
1470 mutt_error (_("You are on the first message."));
1474 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1475 menu->current = menu->oldcurrent;
1476 if (menu->menu == MENU_MAIN)
1477 mutt_error (_("No undeleted messages."));
1479 else if (menu->menu == MENU_PAGER) {
1480 op = OP_DISPLAY_MESSAGE;
1484 menu->redraw = REDRAW_MOTION;
1491 if (menu->current < 1) {
1492 if (menu->menu == MENU_MAIN)
1493 mutt_error (_("You are on the first message."));
1498 if (menu->menu == MENU_PAGER) {
1499 op = OP_DISPLAY_MESSAGE;
1503 menu->redraw = REDRAW_MOTION;
1506 case OP_DECRYPT_COPY:
1507 case OP_DECRYPT_SAVE:
1508 case OP_COPY_MESSAGE:
1510 case OP_DECODE_COPY:
1511 case OP_DECODE_SAVE:
1514 if (mutt_save_message (tag ? NULL : CURHDR,
1515 (op == OP_DECRYPT_SAVE) ||
1516 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1517 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1518 (op == OP_DECRYPT_SAVE)
1519 || (op == OP_DECRYPT_COPY)
1520 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1527 menu->redraw |= REDRAW_INDEX;
1528 else if (option (OPTRESOLVE)) {
1529 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1530 menu->current = menu->oldcurrent;
1531 menu->redraw |= REDRAW_CURRENT;
1534 menu->redraw |= REDRAW_MOTION_RESYNCH;
1537 menu->redraw |= REDRAW_CURRENT;
1541 case OP_MAIN_NEXT_NEW:
1542 case OP_MAIN_NEXT_UNREAD:
1543 case OP_MAIN_PREV_NEW:
1544 case OP_MAIN_PREV_UNREAD:
1545 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1546 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1549 int first_unread = -1;
1557 for (j = 0; j != Context->vcount; j++) {
1558 #define CURHDRi Context->hdrs[Context->v2r[i]]
1559 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1560 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1562 if (i > Context->vcount - 1) {
1563 mutt_message _("Search wrapped to top.");
1571 mutt_message _("Search wrapped to bottom.");
1573 i = Context->vcount - 1;
1577 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1578 if (UNREAD (CURHDRi) && first_unread == -1)
1580 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1583 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1584 if (first_unread == -1)
1586 if ((!CURHDRi->old) && first_new == -1)
1590 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1593 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1594 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1595 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1600 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1601 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1602 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1604 menu->current = first_new;
1605 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1606 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1607 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1608 && first_unread != -1)
1609 menu->current = first_unread;
1611 if (menu->current == -1) {
1612 menu->current = menu->oldcurrent;
1613 mutt_error ("%s%s.",
1614 (op == OP_MAIN_NEXT_NEW
1616 OP_MAIN_PREV_NEW) ? _("No new messages") :
1617 _("No unread messages"),
1618 Context->pattern ? _(" in this limited view") : "");
1620 else if (menu->menu == MENU_PAGER) {
1621 op = OP_DISPLAY_MESSAGE;
1625 menu->redraw = REDRAW_MOTION;
1628 case OP_FLAG_MESSAGE:
1634 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1637 for (j = 0; j < Context->vcount; j++) {
1638 if (Context->hdrs[Context->v2r[j]]->tagged)
1639 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1640 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1643 menu->redraw |= REDRAW_INDEX;
1646 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1647 if (option (OPTRESOLVE)) {
1648 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1649 menu->current = menu->oldcurrent;
1650 menu->redraw = REDRAW_CURRENT;
1653 menu->redraw = REDRAW_MOTION_RESYNCH;
1656 menu->redraw = REDRAW_CURRENT;
1658 menu->redraw |= REDRAW_STATUS;
1667 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1670 for (j = 0; j < Context->vcount; j++) {
1671 if (Context->hdrs[Context->v2r[j]]->tagged) {
1672 if (Context->hdrs[Context->v2r[j]]->read ||
1673 Context->hdrs[Context->v2r[j]]->old)
1674 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1677 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1681 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1684 if (CURHDR->read || CURHDR->old)
1685 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1687 mutt_set_flag (Context, CURHDR, M_READ, 1);
1689 if (option (OPTRESOLVE)) {
1690 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1691 menu->current = menu->oldcurrent;
1692 menu->redraw = REDRAW_CURRENT;
1695 menu->redraw = REDRAW_MOTION_RESYNCH;
1698 menu->redraw = REDRAW_CURRENT;
1699 menu->redraw |= REDRAW_STATUS;
1703 case OP_TOGGLE_WRITE:
1706 if (mx_toggle_write (Context) == 0)
1707 menu->redraw |= REDRAW_STATUS;
1710 case OP_MAIN_NEXT_THREAD:
1711 case OP_MAIN_NEXT_SUBTHREAD:
1712 case OP_MAIN_PREV_THREAD:
1713 case OP_MAIN_PREV_SUBTHREAD:
1718 case OP_MAIN_NEXT_THREAD:
1719 menu->current = mutt_next_thread (CURHDR);
1722 case OP_MAIN_NEXT_SUBTHREAD:
1723 menu->current = mutt_next_subthread (CURHDR);
1726 case OP_MAIN_PREV_THREAD:
1727 menu->current = mutt_previous_thread (CURHDR);
1730 case OP_MAIN_PREV_SUBTHREAD:
1731 menu->current = mutt_previous_subthread (CURHDR);
1735 if (menu->current < 0) {
1736 menu->current = menu->oldcurrent;
1737 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1738 mutt_error (_("No more threads."));
1741 mutt_error (_("You are on the first thread."));
1743 else if (menu->menu == MENU_PAGER) {
1744 op = OP_DISPLAY_MESSAGE;
1748 menu->redraw = REDRAW_MOTION;
1751 case OP_MAIN_PARENT_MESSAGE:
1756 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1757 menu->current = menu->oldcurrent;
1759 else if (menu->menu == MENU_PAGER) {
1760 op = OP_DISPLAY_MESSAGE;
1764 menu->redraw = REDRAW_MOTION;
1767 case OP_MAIN_SET_FLAG:
1768 case OP_MAIN_CLEAR_FLAG:
1774 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1776 menu->redraw = REDRAW_STATUS;
1778 menu->redraw |= REDRAW_INDEX;
1779 else if (option (OPTRESOLVE)) {
1780 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1781 menu->current = menu->oldcurrent;
1782 menu->redraw |= REDRAW_CURRENT;
1785 menu->redraw |= REDRAW_MOTION_RESYNCH;
1788 menu->redraw |= REDRAW_CURRENT;
1792 case OP_MAIN_COLLAPSE_THREAD:
1796 if ((Sort & SORT_MASK) != SORT_THREADS) {
1797 mutt_error (_("Threading is not enabled."));
1802 if (CURHDR->collapsed) {
1803 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1804 mutt_set_virtual (Context);
1805 if (option (OPTUNCOLLAPSEJUMP))
1806 menu->current = mutt_thread_next_unread (Context, CURHDR);
1808 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1809 menu->current = mutt_collapse_thread (Context, CURHDR);
1810 mutt_set_virtual (Context);
1813 mutt_error (_("Thread contains unread messages."));
1818 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1822 case OP_MAIN_COLLAPSE_ALL:
1826 if ((Sort & SORT_MASK) != SORT_THREADS) {
1827 mutt_error (_("Threading is not enabled."));
1834 THREAD *thread, *top;
1837 if (CURHDR->collapsed)
1838 final = mutt_uncollapse_thread (Context, CURHDR);
1839 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1840 final = mutt_collapse_thread (Context, CURHDR);
1842 final = CURHDR->virtual;
1844 base = Context->hdrs[Context->v2r[final]];
1846 top = Context->tree;
1847 Context->collapsed = !Context->collapsed;
1848 while ((thread = top) != NULL) {
1849 while (!thread->message)
1850 thread = thread->child;
1851 h = thread->message;
1853 if (h->collapsed != Context->collapsed) {
1855 mutt_uncollapse_thread (Context, h);
1856 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1857 mutt_collapse_thread (Context, h);
1862 mutt_set_virtual (Context);
1863 for (j = 0; j < Context->vcount; j++) {
1864 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1870 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1874 /* --------------------------------------------------------------------
1875 * These functions are invoked directly from the internal-pager
1878 case OP_BOUNCE_MESSAGE:
1883 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1886 case OP_CREATE_ALIAS:
1888 mutt_create_alias (Context
1889 && Context->vcount ? CURHDR->env : NULL, NULL);
1890 MAYBE_REDRAW (menu->redraw);
1891 menu->redraw |= REDRAW_CURRENT;
1896 mutt_query_menu (NULL, 0);
1897 MAYBE_REDRAW (menu->redraw);
1900 case OP_PURGE_MESSAGE:
1907 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1910 mutt_tag_set_flag (M_DELETE, 1);
1911 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1912 if (option (OPTDELETEUNTAG))
1913 mutt_tag_set_flag (M_TAG, 0);
1914 menu->redraw = REDRAW_INDEX;
1917 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1918 mutt_set_flag (Context, CURHDR, M_PURGED,
1919 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1920 if (option (OPTDELETEUNTAG))
1921 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1922 if (option (OPTRESOLVE)) {
1923 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1924 menu->current = menu->oldcurrent;
1925 menu->redraw = REDRAW_CURRENT;
1927 else if (menu->menu == MENU_PAGER) {
1928 op = OP_DISPLAY_MESSAGE;
1932 menu->redraw |= REDRAW_MOTION_RESYNCH;
1935 menu->redraw = REDRAW_CURRENT;
1937 menu->redraw |= REDRAW_STATUS;
1940 case OP_DELETE_THREAD:
1941 case OP_DELETE_SUBTHREAD:
1947 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1949 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1950 op == OP_DELETE_THREAD ? 0 : 1);
1953 if (option (OPTDELETEUNTAG))
1954 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1955 op == OP_DELETE_THREAD ? 0 : 1);
1956 if (option (OPTRESOLVE))
1957 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1958 menu->current = menu->oldcurrent;
1959 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1965 if (Context && Context->magic == M_NNTP) {
1966 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1967 ((NNTP_DATA *) Context->data)->group))
1968 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1973 case OP_DISPLAY_ADDRESS:
1977 mutt_display_address (CURHDR->env);
1980 case OP_ENTER_COMMAND:
1982 CurrentMenu = MENU_MAIN;
1983 mutt_enter_command ();
1984 mutt_check_rescore (Context);
1985 if (option (OPTFORCEREDRAWINDEX))
1986 menu->redraw = REDRAW_FULL;
1987 unset_option (OPTFORCEREDRAWINDEX);
1988 unset_option (OPTFORCEREDRAWPAGER);
1991 case OP_EDIT_MESSAGE:
1998 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
2000 if (option (OPTPGPAUTODEC)
2001 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2002 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2003 mutt_edit_message (Context, tag ? NULL : CURHDR);
2004 menu->redraw = REDRAW_FULL;
2008 case OP_FORWARD_MESSAGE:
2014 if (option (OPTPGPAUTODEC) &&
2015 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2016 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2017 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2018 menu->redraw = REDRAW_FULL;
2022 case OP_FORGET_PASSPHRASE:
2023 crypt_forget_passphrase ();
2026 case OP_GROUP_REPLY:
2032 if (option (OPTPGPAUTODEC) &&
2033 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2034 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2036 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2037 tag ? NULL : CURHDR);
2038 menu->redraw = REDRAW_FULL;
2047 if (option (OPTPGPAUTODEC) &&
2048 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2049 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2051 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2052 tag ? NULL : CURHDR);
2053 menu->redraw = REDRAW_FULL;
2059 ci_send_message (0, NULL, NULL, Context, NULL);
2060 menu->redraw = REDRAW_FULL;
2065 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2066 menu->redraw = REDRAW_FULL;
2070 case OP_EXTRACT_KEYS:
2073 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2074 menu->redraw = REDRAW_FULL;
2078 case OP_CHECK_TRADITIONAL:
2081 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2082 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2084 if (menu->menu == MENU_PAGER) {
2085 op = OP_DISPLAY_MESSAGE;
2094 mutt_pipe_message (tag ? NULL : CURHDR);
2096 /* in an IMAP folder index with imap_peek=no, piping could change
2097 * * new or old messages status to read. Redraw what's needed.
2099 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2100 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2103 MAYBE_REDRAW (menu->redraw);
2110 mutt_print_message (tag ? NULL : CURHDR);
2112 /* in an IMAP folder index with imap_peek=no, piping could change
2113 * * new or old messages status to read. Redraw what's needed.
2115 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2116 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2121 case OP_MAIN_READ_THREAD:
2122 case OP_MAIN_READ_SUBTHREAD:
2128 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2130 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2131 op == OP_MAIN_READ_THREAD ? 0 : 1);
2134 if (option (OPTRESOLVE)) {
2135 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2136 mutt_next_thread (CURHDR) :
2137 mutt_next_subthread (CURHDR))) == -1)
2138 menu->current = menu->oldcurrent;
2140 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2144 case OP_RECALL_MESSAGE:
2147 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2148 menu->redraw = REDRAW_FULL;
2158 for (j = 0; j < Context->vcount; j++) {
2159 if (Context->hdrs[Context->v2r[j]]->tagged)
2160 mutt_resend_message (NULL, Context,
2161 Context->hdrs[Context->v2r[j]]);
2165 mutt_resend_message (NULL, Context, CURHDR);
2167 menu->redraw = REDRAW_FULL;
2173 case OP_FORWARD_TO_GROUP:
2176 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2177 Context && Context->msgcount == 0) {
2178 mutt_error (_("There are no messages."));
2181 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2182 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2183 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2184 _("Reply by mail as poster prefers?")) !=
2186 if (Context && Context->magic == M_NNTP
2187 && !((NNTP_DATA *) Context->data)->allowed
2188 && query_quadoption (OPT_TOMODERATED,
2190 ("Posting to this group not allowed, may be moderated. Continue?"))
2194 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2197 if (op == OP_FOLLOWUP)
2198 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2199 tag ? NULL : CURHDR);
2201 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2202 tag ? NULL : CURHDR);
2204 menu->redraw = REDRAW_FULL;
2215 if (option (OPTPGPAUTODEC) &&
2216 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2217 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2219 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2220 menu->redraw = REDRAW_FULL;
2223 case OP_SHELL_ESCAPE:
2225 mutt_shell_escape ();
2226 MAYBE_REDRAW (menu->redraw);
2230 case OP_TAG_SUBTHREAD:
2234 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2235 op == OP_TAG_THREAD ? 0 : 1);
2238 if (option (OPTRESOLVE)) {
2239 menu->current = mutt_next_thread (CURHDR);
2241 if (menu->current == -1)
2242 menu->current = menu->oldcurrent;
2244 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2254 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2257 mutt_tag_set_flag (M_DELETE, 0);
2258 mutt_tag_set_flag (M_PURGED, 0);
2259 menu->redraw = REDRAW_INDEX;
2262 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2263 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2264 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2266 menu->redraw = REDRAW_MOTION_RESYNCH;
2269 menu->redraw = REDRAW_CURRENT;
2271 menu->redraw |= REDRAW_STATUS;
2274 case OP_UNDELETE_THREAD:
2275 case OP_UNDELETE_SUBTHREAD:
2281 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2283 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2284 op == OP_UNDELETE_THREAD ? 0 : 1)
2285 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2286 op == OP_UNDELETE_THREAD ? 0 : 1);
2289 if (option (OPTRESOLVE)) {
2290 if (op == OP_UNDELETE_THREAD)
2291 menu->current = mutt_next_thread (CURHDR);
2293 menu->current = mutt_next_subthread (CURHDR);
2295 if (menu->current == -1)
2296 menu->current = menu->oldcurrent;
2298 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2307 if (option (OPTFORCEBUFFYCHECK))
2310 menu->redraw = REDRAW_FULL;
2313 case OP_VIEW_ATTACHMENTS:
2316 mutt_view_attachments (CURHDR);
2317 if (CURHDR->attach_del)
2318 Context->changed = 1;
2319 menu->redraw = REDRAW_FULL;
2329 case OP_REBUILD_CACHE:
2330 mx_rebuild_cache ();
2333 case OP_SIDEBAR_SCROLL_UP:
2334 case OP_SIDEBAR_SCROLL_DOWN:
2335 case OP_SIDEBAR_NEXT:
2336 case OP_SIDEBAR_PREV:
2337 case OP_SIDEBAR_NEXT_NEW:
2338 case OP_SIDEBAR_PREV_NEW:
2339 sidebar_scroll (op, menu->menu);
2342 if (menu->menu == MENU_MAIN)
2343 km_error_key (MENU_MAIN);
2346 if (menu->menu == MENU_PAGER) {
2347 menu->menu = MENU_MAIN;
2348 menu->redraw = REDRAW_FULL;
2350 set_option (OPTWEED); /* turn header weeding back on. */
2360 /* Close all open IMAP connections */
2364 /* Close all open NNTP connections */
2372 mutt_menuDestroy (&menu);
2376 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2383 for (color = ColorIndexList; color; color = color->next)
2384 if (mutt_pattern_exec
2385 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2386 curhdr->pair = color->pair;
2389 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];