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.
18 #include "mutt_curses.h"
20 #include "mutt_menu.h"
33 #include "imap_private.h"
36 #include "mutt_crypt.h"
45 #include "lib/debug.h"
55 static const char *No_mailbox_is_open = N_("No mailbox is open.");
56 static const char *There_are_no_messages = N_("There are no messages.");
57 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
58 static const char *Function_not_permitted_in_attach_message_mode =
59 N_("Function not permitted in attach-message mode.");
60 static const char *No_visible = N_("No visible messages.");
62 #define CHECK_MSGCOUNT if (!Context) \
65 mutt_error(_(No_mailbox_is_open)); \
68 else if (!Context->msgcount) \
71 mutt_error(_(There_are_no_messages)); \
75 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
78 mutt_error(_(No_visible)); \
83 #define CHECK_READONLY if (Context->readonly) \
86 mutt_error(_(Mailbox_is_read_only)); \
90 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
93 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
97 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
98 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
99 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
101 extern const char *ReleaseDate;
102 extern size_t UngetCount;
104 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
107 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
108 int edgemsgno, reverse = Sort & SORT_REVERSE;
109 HEADER *h = Context->hdrs[Context->v2r[num]];
112 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
113 flag |= M_FORMAT_TREE; /* display the thread tree */
114 if (h->display_subject)
115 flag |= M_FORMAT_FORCESUBJ;
118 if (menu->top + menu->pagelen > menu->max)
119 edgemsgno = Context->v2r[menu->max - 1];
121 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
124 edgemsgno = Context->v2r[menu->top];
126 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
130 /* if no ancestor is visible on current screen, provisionally force
132 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
134 flag |= M_FORMAT_FORCESUBJ;
137 else if (tmp->message->virtual >= 0)
140 if (flag & M_FORMAT_FORCESUBJ) {
141 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
145 /* ...but if a previous sibling is available, don't force it */
146 if (reverse ? tmp->message->msgno >
147 edgemsgno : tmp->message->msgno < edgemsgno)
149 else if (tmp->message->virtual >= 0) {
150 flag &= ~M_FORMAT_FORCESUBJ;
158 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
161 int index_color (int index_no)
163 HEADER *h = Context->hdrs[Context->v2r[index_no]];
168 mutt_set_header_color (Context, h);
172 static int ci_next_undeleted (int msgno)
176 for (i = msgno + 1; i < Context->vcount; i++)
177 if (!Context->hdrs[Context->v2r[i]]->deleted)
182 static int ci_previous_undeleted (int msgno)
186 for (i = msgno - 1; i >= 0; i--)
187 if (!Context->hdrs[Context->v2r[i]]->deleted)
192 /* Return the index of the first new message, or failing that, the first
195 static int ci_first_message (void)
199 if (Context && Context->msgcount) {
200 for (i = 0; i < Context->vcount; i++) {
201 if (!Context->hdrs[Context->v2r[i]]->read &&
202 !Context->hdrs[Context->v2r[i]]->deleted) {
203 if (!Context->hdrs[Context->v2r[i]]->old)
212 /* If Sort is reverse and not threaded, the latest message is first.
213 * If Sort is threaded, the latest message is first iff exactly one
214 * of Sort and SortAux are reverse.
216 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
217 ((Sort & SORT_MASK) == SORT_THREADS &&
218 ((Sort ^ SortAux) & SORT_REVERSE)))
221 return (Context->vcount ? Context->vcount - 1 : 0);
226 /* This should be in mx.c, but it only gets used here. */
227 static int mx_toggle_write (CONTEXT * ctx)
233 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
238 if (ctx->dontwrite) {
240 mutt_message (_("Changes to folder will be written on folder exit."));
244 mutt_message (_("Changes to folder will not be written."));
250 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
251 int oldcount, int index_hint)
253 /* store pointers to the newly added messages */
254 HEADER **save_new = NULL;
257 /* take note of the current message */
259 if (menu->current < Context->vcount)
260 menu->oldcurrent = index_hint;
262 oldcount = 0; /* invalid message number! */
265 /* We are in a limited view. Check if the new message(s) satisfy
266 * the limit criteria. If they do, set their virtual msgno so that
267 * they will be visible in the limited view */
268 if (Context->pattern) {
269 #define THIS_BODY Context->hdrs[j]->content
270 if (oldcount || check == M_REOPENED) {
271 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount;
273 if (mutt_pattern_exec
274 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
276 Context->hdrs[j]->virtual = Context->vcount;
277 Context->v2r[Context->vcount] = j;
278 Context->hdrs[j]->limited = 1;
281 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
288 /* save the list of new messages */
289 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
291 (HEADER **) safe_malloc (sizeof (HEADER *) *
292 (Context->msgcount - oldcount));
293 for (j = oldcount; j < Context->msgcount; j++)
294 save_new[j - oldcount] = Context->hdrs[j];
297 /* if the mailbox was reopened, need to rethread from scratch */
298 mutt_sort_headers (Context, (check == M_REOPENED));
300 /* uncollapse threads with new mail */
301 if ((Sort & SORT_MASK) == SORT_THREADS) {
302 if (check == M_REOPENED) {
305 Context->collapsed = 0;
307 for (h = Context->tree; h; h = h->next) {
308 for (j = h; !j->message; j = j->child);
309 mutt_uncollapse_thread (Context, j->message);
311 mutt_set_virtual (Context);
314 for (j = 0; j < Context->msgcount - oldcount; j++) {
317 for (k = 0; k < Context->msgcount; k++) {
318 HEADER *h = Context->hdrs[k];
320 if (h == save_new[j] && (!Context->pattern || h->limited))
321 mutt_uncollapse_thread (Context, h);
325 mutt_set_virtual (Context);
331 /* restore the current message to the message it was pointing to */
332 for (j = 0; j < Context->vcount; j++) {
333 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
340 if (menu->current < 0)
341 menu->current = ci_first_message ();
345 static void resort_index (MUTTMENU * menu)
348 HEADER *current = CURHDR;
351 mutt_sort_headers (Context, 0);
352 /* Restore the current message */
354 for (i = 0; i < Context->vcount; i++) {
355 if (Context->hdrs[Context->v2r[i]] == current) {
361 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
362 menu->current = mutt_parent_message (Context, current);
364 if (menu->current < 0)
365 menu->current = ci_first_message ();
367 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
370 struct mapping_t IndexHelp[] = {
371 {N_("Quit"), OP_QUIT},
372 {N_("Del"), OP_DELETE},
373 {N_("Undel"), OP_UNDELETE},
374 {N_("Save"), OP_SAVE},
375 {N_("Mail"), OP_MAIL},
376 {N_("Reply"), OP_REPLY},
377 {N_("Group"), OP_GROUP_REPLY},
378 {N_("Help"), OP_HELP},
383 struct mapping_t IndexNewsHelp[] = {
384 {N_("Quit"), OP_QUIT},
385 {N_("Del"), OP_DELETE},
386 {N_("Undel"), OP_UNDELETE},
387 {N_("Save"), OP_SAVE},
388 {N_("Post"), OP_POST},
389 {N_("Followup"), OP_FOLLOWUP},
390 {N_("Catchup"), OP_CATCHUP},
391 {N_("Help"), OP_HELP},
396 /* This function handles the message index window as well as commands returned
397 * from the pager (MENU_PAGER).
399 int mutt_index_menu (void)
401 char buf[LONG_STRING], helpstr[SHORT_STRING];
404 int done = 0; /* controls when to exit the "event" loop */
406 int tag = 0; /* has the tag-prefix command been pressed? */
411 char *cp; /* temporary variable. */
412 int index_hint; /* used to restore cursor position */
413 int do_buffy_notify = 1;
414 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
415 int attach_msg = option (OPTATTACHMSG);
417 menu = mutt_new_menu ();
418 menu->menu = MENU_MAIN;
420 menu->pagelen = LINES - 3;
421 menu->make_entry = index_make_entry;
422 menu->color = index_color;
423 menu->current = ci_first_message ();
424 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
427 && (Context->magic ==
428 M_NNTP)) ? IndexNewsHelp :
433 buffy_check (1); /* force the buffy check after we enter the folder */
434 /* record folder we open to place sidebar indicator properly */
435 if (Context && Context->path)
436 sidebar_set_current (Context->path);
440 tag = 0; /* clear the tag-prefix */
442 menu->max = Context ? Context->vcount : 0;
443 oldcount = Context ? Context->msgcount : 0;
445 /* check if we need to resort the index because just about
446 * any 'op' below could do mutt_enter_command(), either here or
447 * from any new menu launched, and change $sort/$sort_aux
449 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
452 if (option (OPTREDRAWTREE) && Context && Context->msgcount
453 && (Sort & SORT_MASK) == SORT_THREADS) {
454 mutt_draw_tree (Context);
455 menu->redraw |= REDRAW_STATUS;
456 unset_option (OPTREDRAWTREE);
459 if (Context && !attach_msg) {
462 /* check for new mail in the mailbox. If nonzero, then something has
463 * changed about the file (either we got new mail or the file was
464 * modified underneath us.)
468 imap_allow_reopen (Context);
471 index_hint = (Context->vcount && menu->current >= 0
472 && menu->current < Context->vcount) ? CURHDR->index : 0;
474 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
475 if (!Context->path) {
476 /* fatal error occurred */
478 menu->redraw = REDRAW_FULL;
480 set_option (OPTSEARCHINVALID);
482 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
483 update_index (menu, Context, check, oldcount, index_hint);
485 /* notify the user of new mail */
486 if (check == M_REOPENED)
488 ("Mailbox was externally modified. Flags may be wrong."));
489 else if (check == M_NEW_MAIL) {
490 /* on new mail: redraw sidebar */
491 sidebar_draw (CurrentMenu);
492 mutt_message (_("New mail in this mailbox."));
494 if (option (OPTBEEPNEW))
497 else if (check == M_FLAGS)
498 mutt_message (_("Mailbox was externally modified."));
500 /* avoid the message being overwritten by buffy */
503 menu->redraw = REDRAW_FULL;
504 menu->max = Context->vcount;
506 set_option (OPTSEARCHINVALID);
512 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) {
556 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
558 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
559 SETCOLOR (MT_COLOR_STATUS);
560 BKGDSET (MT_COLOR_STATUS);
561 mutt_paddstr (COLS, 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 op = km_dokey (MENU_MAIN);
590 debug_print (4, ("Got op %d\n", op));
592 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
595 mutt_resize_screen ();
596 menu->redraw = REDRAW_FULL;
597 menu->menu = MENU_MAIN;
599 menu->top = 0; /* so we scroll the right amount */
601 * force a real complete redraw. clrtobot() doesn't seem to be able
602 * to handle every case without this.
604 clearok (stdscr, TRUE);
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 LIST *ref = CURHDR->env->references;
757 mutt_error (_("Article has no parent reference!"));
761 strfcpy (buf, ref->data, sizeof (buf));
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, i;
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 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
809 if (op == OP_RECONSTRUCT_THREAD) {
810 LIST *ref = CURHDR->env->references;
813 nntp_check_msgid (Context, ref->data);
814 /* the last msgid in References is the root message */
816 strfcpy (buf, ref->data, sizeof (buf));
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;
909 case OP_MAIN_FETCH_MAIL:
913 menu->redraw = REDRAW_FULL;
919 mutt_help (MENU_MAIN);
920 menu->redraw = REDRAW_FULL;
923 case OP_MAIN_SHOW_LIMIT:
925 if (!Context->pattern)
926 mutt_message (_("No limit pattern is in effect."));
931 /* i18n: ask for a limit to apply */
932 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
933 mutt_message ("%s", buf);
941 menu->oldcurrent = (Context->vcount && menu->current >= 0
943 Context->vcount) ? CURHDR->index : -1;
944 if (op == OP_TOGGLE_READ) {
945 char buf[LONG_STRING];
947 if (!Context->pattern
948 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
949 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
950 Context->pattern ? Context->pattern : ".*");
951 set_option (OPTHIDEREAD);
954 strfcpy (buf, Context->pattern + 8, sizeof (buf));
955 if (!*buf || strncmp (buf, ".*", 2) == 0)
956 snprintf (buf, sizeof (buf), "~A");
957 unset_option (OPTHIDEREAD);
959 FREE (&Context->pattern);
960 Context->pattern = safe_strdup (buf);
962 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
963 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
965 if (menu->oldcurrent >= 0) {
966 /* try to find what used to be the current message */
968 for (i = 0; i < Context->vcount; i++)
969 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
973 if (menu->current < 0)
978 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
979 if ((Sort & SORT_MASK) == SORT_THREADS)
980 mutt_draw_tree (Context);
981 menu->redraw = REDRAW_FULL;
993 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == 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.
1099 case OP_MAIN_IMAP_FETCH:
1100 if (Context->magic == M_IMAP)
1101 imap_check_mailbox (Context, &index_hint, 1);
1105 case OP_MAIN_SYNC_FOLDER:
1107 if (Context && !Context->msgcount)
1114 int oldvcount = Context->vcount;
1115 int oldcount = Context->msgcount;
1119 /* calculate the number of messages _above_ the cursor,
1120 * so we can keep the cursor on the current message
1122 for (j = 0; j <= menu->current; j++) {
1123 if (Context->hdrs[Context->v2r[j]]->deleted)
1127 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1128 if (Context->vcount != oldvcount)
1129 menu->current -= dcount;
1130 set_option (OPTSEARCHINVALID);
1132 else if (check == M_NEW_MAIL || check == M_REOPENED)
1133 update_index (menu, Context, check, oldcount, index_hint);
1136 * do a sanity check even if mx_sync_mailbox failed.
1139 if (menu->current < 0 || menu->current >= Context->vcount)
1140 menu->current = ci_first_message ();
1143 /* check for a fatal error, or all messages deleted */
1147 /* if we were in the pager, redisplay the message */
1148 if (menu->menu == MENU_PAGER) {
1149 op = OP_DISPLAY_MESSAGE;
1153 menu->redraw = REDRAW_FULL;
1156 case OP_SIDEBAR_OPEN:
1157 case OP_MAIN_CHANGE_FOLDER:
1158 case OP_MAIN_CHANGE_FOLDER_READONLY:
1160 case OP_MAIN_CHANGE_GROUP:
1161 case OP_MAIN_CHANGE_GROUP_READONLY:
1163 if (attach_msg || option (OPTREADONLY) ||
1165 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1167 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1173 cp = _("Open mailbox in read-only mode");
1175 cp = _("Open mailbox");
1179 unset_option (OPTNEWS);
1180 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1181 set_option (OPTNEWS);
1182 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1185 cp = _("Open newsgroup in read-only mode");
1187 cp = _("Open newsgroup");
1193 if (Context && Context->path)
1194 strncpy (buf, Context->path, sizeof (buf));
1195 if (op != OP_SIDEBAR_OPEN)
1196 buffy_next (buf, sizeof (buf));
1199 if (op == OP_SIDEBAR_OPEN) {
1200 strncpy (buf, NONULL(sidebar_get_current ()), sizeof (buf));
1202 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1206 CLEARLINE (LINES - 1);
1211 if (option (OPTNEWS)) {
1212 unset_option (OPTNEWS);
1213 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1217 mutt_expand_path (buf, sizeof (buf));
1218 if (mx_get_magic (buf) <= 0) {
1219 mutt_error (_("%s is not a mailbox."), buf);
1222 str_replace (&CurrentFolder, buf);
1227 #ifdef USE_COMPRESSED
1228 if (Context->compressinfo && Context->realpath)
1229 str_replace (&LastFolder, Context->realpath);
1233 str_replace (&LastFolder, Context->path);
1234 oldcount = Context ? Context->msgcount : 0;
1236 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1237 if (check == M_NEW_MAIL || check == M_REOPENED)
1238 update_index (menu, Context, check, oldcount, index_hint);
1240 set_option (OPTSEARCHINVALID);
1241 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1249 /* Set CurrentMenu to MENU_MAIN before executing any folder
1250 * hooks so that all the index menu functions are available to
1254 CurrentMenu = MENU_MAIN;
1255 mutt_folder_hook (buf);
1257 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1258 menu->current = ci_first_message ();
1262 sidebar_set_current (buf);
1265 /* buffy_check() must be done with mail-reader mode! */
1266 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1268 && (Context->magic ==
1269 M_NNTP)) ? IndexNewsHelp :
1272 mutt_clear_error ();
1273 buffy_check (1); /* force the buffy check after we have changed
1275 menu->redraw = REDRAW_FULL;
1276 set_option (OPTSEARCHINVALID);
1279 case OP_DISPLAY_MESSAGE:
1280 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1285 * toggle the weeding of headers so that a user can press the key
1286 * again while reading the message.
1288 if (op == OP_DISPLAY_HEADERS)
1289 toggle_option (OPTWEED);
1291 unset_option (OPTNEEDRESORT);
1293 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1294 mutt_uncollapse_thread (Context, CURHDR);
1295 mutt_set_virtual (Context);
1296 if (option (OPTUNCOLLAPSEJUMP))
1297 menu->current = mutt_thread_next_unread (Context, CURHDR);
1300 if (option (OPTPGPAUTODEC) &&
1301 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1302 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1304 if ((op = mutt_display_message (CURHDR)) == -1) {
1305 unset_option (OPTNEEDRESORT);
1309 menu->menu = MENU_PAGER;
1310 menu->oldcurrent = menu->current;
1316 if (menu->menu == MENU_MAIN && attach_msg) {
1321 if ((menu->menu == MENU_MAIN)
1322 && (query_quadoption (OPT_QUIT,
1323 _("Exit Mutt-ng without saving?")) == M_YES))
1326 mx_fastclose_mailbox (Context);
1338 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1339 /* if we were in the pager, redisplay the message */
1340 if (menu->menu == MENU_PAGER) {
1341 op = OP_DISPLAY_MESSAGE;
1345 menu->redraw = REDRAW_CURRENT;
1348 case OP_MAIN_BREAK_THREAD:
1354 if ((Sort & SORT_MASK) != SORT_THREADS)
1355 mutt_error (_("Threading is not enabled."));
1359 HEADER *oldcur = CURHDR;
1361 mutt_break_thread (CURHDR);
1362 mutt_sort_headers (Context, 1);
1363 menu->current = oldcur->virtual;
1366 Context->changed = 1;
1367 mutt_message _("Thread broken");
1369 if (menu->menu == MENU_PAGER) {
1370 op = OP_DISPLAY_MESSAGE;
1374 menu->redraw |= REDRAW_INDEX;
1378 case OP_MAIN_LINK_THREADS:
1384 if ((Sort & SORT_MASK) != SORT_THREADS)
1385 mutt_error (_("Threading is not enabled."));
1387 else if (!CURHDR->env->message_id)
1388 mutt_error (_("No Message-ID: header available to link thread"));
1390 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1391 mutt_error (_("First, please tag a message to be linked here"));
1394 HEADER *oldcur = CURHDR;
1396 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1398 mutt_sort_headers (Context, 1);
1399 menu->current = oldcur->virtual;
1401 Context->changed = 1;
1402 mutt_message _("Threads linked");
1405 mutt_error (_("No thread linked"));
1408 if (menu->menu == MENU_PAGER) {
1409 op = OP_DISPLAY_MESSAGE;
1413 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1416 case OP_MAIN_NEXT_UNDELETED:
1420 if (menu->current >= Context->vcount - 1) {
1421 if (menu->menu == MENU_MAIN)
1422 mutt_error (_("You are on the last message."));
1426 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1427 menu->current = menu->oldcurrent;
1428 if (menu->menu == MENU_MAIN)
1429 mutt_error (_("No undeleted messages."));
1431 else if (menu->menu == MENU_PAGER) {
1432 op = OP_DISPLAY_MESSAGE;
1436 menu->redraw = REDRAW_MOTION;
1443 if (menu->current >= Context->vcount - 1) {
1444 if (menu->menu == MENU_MAIN)
1445 mutt_error (_("You are on the last message."));
1450 if (menu->menu == MENU_PAGER) {
1451 op = OP_DISPLAY_MESSAGE;
1455 menu->redraw = REDRAW_MOTION;
1458 case OP_MAIN_PREV_UNDELETED:
1462 if (menu->current < 1) {
1463 mutt_error (_("You are on the first message."));
1467 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1468 menu->current = menu->oldcurrent;
1469 if (menu->menu == MENU_MAIN)
1470 mutt_error (_("No undeleted messages."));
1472 else if (menu->menu == MENU_PAGER) {
1473 op = OP_DISPLAY_MESSAGE;
1477 menu->redraw = REDRAW_MOTION;
1484 if (menu->current < 1) {
1485 if (menu->menu == MENU_MAIN)
1486 mutt_error (_("You are on the first message."));
1491 if (menu->menu == MENU_PAGER) {
1492 op = OP_DISPLAY_MESSAGE;
1496 menu->redraw = REDRAW_MOTION;
1499 case OP_DECRYPT_COPY:
1500 case OP_DECRYPT_SAVE:
1504 case OP_COPY_MESSAGE:
1506 case OP_DECODE_COPY:
1507 case OP_DECODE_SAVE:
1510 if (mutt_save_message (tag ? NULL : CURHDR,
1511 (op == OP_DECRYPT_SAVE) ||
1512 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1513 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1514 (op == OP_DECRYPT_SAVE)
1515 || (op == OP_DECRYPT_COPY)
1516 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1523 menu->redraw |= REDRAW_INDEX;
1524 else if (option (OPTRESOLVE)) {
1525 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1526 menu->current = menu->oldcurrent;
1527 menu->redraw |= REDRAW_CURRENT;
1530 menu->redraw |= REDRAW_MOTION_RESYNCH;
1533 menu->redraw |= REDRAW_CURRENT;
1537 case OP_MAIN_NEXT_NEW:
1538 case OP_MAIN_NEXT_UNREAD:
1539 case OP_MAIN_PREV_NEW:
1540 case OP_MAIN_PREV_UNREAD:
1541 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1542 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1545 int first_unread = -1;
1553 for (j = 0; j != Context->vcount; j++) {
1554 #define CURHDRi Context->hdrs[Context->v2r[i]]
1555 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1556 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1558 if (i > Context->vcount - 1) {
1559 mutt_message _("Search wrapped to top.");
1567 mutt_message _("Search wrapped to bottom.");
1569 i = Context->vcount - 1;
1573 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1574 if (UNREAD (CURHDRi) && first_unread == -1)
1576 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1579 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1580 if (first_unread == -1)
1582 if ((!CURHDRi->old) && first_new == -1)
1586 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1589 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1590 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1591 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1596 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1597 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1598 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1600 menu->current = first_new;
1601 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1602 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1603 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1604 && first_unread != -1)
1605 menu->current = first_unread;
1607 if (menu->current == -1) {
1608 menu->current = menu->oldcurrent;
1609 mutt_error ("%s%s.",
1610 (op == OP_MAIN_NEXT_NEW
1612 OP_MAIN_PREV_NEW) ? _("No new messages") :
1613 _("No unread messages"),
1614 Context->pattern ? _(" in this limited view") : "");
1616 else if (menu->menu == MENU_PAGER) {
1617 op = OP_DISPLAY_MESSAGE;
1621 menu->redraw = REDRAW_MOTION;
1624 case OP_FLAG_MESSAGE:
1630 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1633 for (j = 0; j < Context->vcount; j++) {
1634 if (Context->hdrs[Context->v2r[j]]->tagged)
1635 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1636 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1639 menu->redraw |= REDRAW_INDEX;
1642 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1643 if (option (OPTRESOLVE)) {
1644 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1645 menu->current = menu->oldcurrent;
1646 menu->redraw = REDRAW_CURRENT;
1649 menu->redraw = REDRAW_MOTION_RESYNCH;
1652 menu->redraw = REDRAW_CURRENT;
1654 menu->redraw |= REDRAW_STATUS;
1663 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1666 for (j = 0; j < Context->vcount; j++) {
1667 if (Context->hdrs[Context->v2r[j]]->tagged) {
1668 if (Context->hdrs[Context->v2r[j]]->read ||
1669 Context->hdrs[Context->v2r[j]]->old)
1670 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1673 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1677 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1680 if (CURHDR->read || CURHDR->old)
1681 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1683 mutt_set_flag (Context, CURHDR, M_READ, 1);
1685 if (option (OPTRESOLVE)) {
1686 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1687 menu->current = menu->oldcurrent;
1688 menu->redraw = REDRAW_CURRENT;
1691 menu->redraw = REDRAW_MOTION_RESYNCH;
1694 menu->redraw = REDRAW_CURRENT;
1695 menu->redraw |= REDRAW_STATUS;
1699 case OP_TOGGLE_WRITE:
1702 if (mx_toggle_write (Context) == 0)
1703 menu->redraw |= REDRAW_STATUS;
1706 case OP_MAIN_NEXT_THREAD:
1707 case OP_MAIN_NEXT_SUBTHREAD:
1708 case OP_MAIN_PREV_THREAD:
1709 case OP_MAIN_PREV_SUBTHREAD:
1714 case OP_MAIN_NEXT_THREAD:
1715 menu->current = mutt_next_thread (CURHDR);
1718 case OP_MAIN_NEXT_SUBTHREAD:
1719 menu->current = mutt_next_subthread (CURHDR);
1722 case OP_MAIN_PREV_THREAD:
1723 menu->current = mutt_previous_thread (CURHDR);
1726 case OP_MAIN_PREV_SUBTHREAD:
1727 menu->current = mutt_previous_subthread (CURHDR);
1731 if (menu->current < 0) {
1732 menu->current = menu->oldcurrent;
1733 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1734 mutt_error (_("No more threads."));
1737 mutt_error (_("You are on the first thread."));
1739 else if (menu->menu == MENU_PAGER) {
1740 op = OP_DISPLAY_MESSAGE;
1744 menu->redraw = REDRAW_MOTION;
1747 case OP_MAIN_PARENT_MESSAGE:
1752 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1753 menu->current = menu->oldcurrent;
1755 else if (menu->menu == MENU_PAGER) {
1756 op = OP_DISPLAY_MESSAGE;
1760 menu->redraw = REDRAW_MOTION;
1763 case OP_MAIN_SET_FLAG:
1764 case OP_MAIN_CLEAR_FLAG:
1770 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1772 menu->redraw = REDRAW_STATUS;
1774 menu->redraw |= REDRAW_INDEX;
1775 else if (option (OPTRESOLVE)) {
1776 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1777 menu->current = menu->oldcurrent;
1778 menu->redraw |= REDRAW_CURRENT;
1781 menu->redraw |= REDRAW_MOTION_RESYNCH;
1784 menu->redraw |= REDRAW_CURRENT;
1788 case OP_MAIN_COLLAPSE_THREAD:
1792 if ((Sort & SORT_MASK) != SORT_THREADS) {
1793 mutt_error (_("Threading is not enabled."));
1798 if (CURHDR->collapsed) {
1799 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1800 mutt_set_virtual (Context);
1801 if (option (OPTUNCOLLAPSEJUMP))
1802 menu->current = mutt_thread_next_unread (Context, CURHDR);
1804 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1805 menu->current = mutt_collapse_thread (Context, CURHDR);
1806 mutt_set_virtual (Context);
1809 mutt_error (_("Thread contains unread messages."));
1814 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1818 case OP_MAIN_COLLAPSE_ALL:
1822 if ((Sort & SORT_MASK) != SORT_THREADS) {
1823 mutt_error (_("Threading is not enabled."));
1830 THREAD *thread, *top;
1833 if (CURHDR->collapsed)
1834 final = mutt_uncollapse_thread (Context, CURHDR);
1835 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1836 final = mutt_collapse_thread (Context, CURHDR);
1838 final = CURHDR->virtual;
1840 base = Context->hdrs[Context->v2r[final]];
1842 top = Context->tree;
1843 Context->collapsed = !Context->collapsed;
1844 while ((thread = top) != NULL) {
1845 while (!thread->message)
1846 thread = thread->child;
1847 h = thread->message;
1849 if (h->collapsed != Context->collapsed) {
1851 mutt_uncollapse_thread (Context, h);
1852 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1853 mutt_collapse_thread (Context, h);
1858 mutt_set_virtual (Context);
1859 for (j = 0; j < Context->vcount; j++) {
1860 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1866 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1870 /* --------------------------------------------------------------------
1871 * These functions are invoked directly from the internal-pager
1874 case OP_BOUNCE_MESSAGE:
1879 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1882 case OP_CREATE_ALIAS:
1884 mutt_create_alias (Context
1885 && Context->vcount ? CURHDR->env : NULL, NULL);
1886 MAYBE_REDRAW (menu->redraw);
1887 menu->redraw |= REDRAW_CURRENT;
1892 mutt_query_menu (NULL, 0);
1893 MAYBE_REDRAW (menu->redraw);
1896 case OP_PURGE_MESSAGE:
1903 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1906 mutt_tag_set_flag (M_DELETE, 1);
1907 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1908 if (option (OPTDELETEUNTAG))
1909 mutt_tag_set_flag (M_TAG, 0);
1910 menu->redraw = REDRAW_INDEX;
1913 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1914 mutt_set_flag (Context, CURHDR, M_PURGED,
1915 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1916 if (option (OPTDELETEUNTAG))
1917 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1918 if (option (OPTRESOLVE)) {
1919 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1920 menu->current = menu->oldcurrent;
1921 menu->redraw = REDRAW_CURRENT;
1923 else if (menu->menu == MENU_PAGER) {
1924 op = OP_DISPLAY_MESSAGE;
1928 menu->redraw |= REDRAW_MOTION_RESYNCH;
1931 menu->redraw = REDRAW_CURRENT;
1933 menu->redraw |= REDRAW_STATUS;
1936 case OP_DELETE_THREAD:
1937 case OP_DELETE_SUBTHREAD:
1943 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1945 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1946 op == OP_DELETE_THREAD ? 0 : 1);
1949 if (option (OPTDELETEUNTAG))
1950 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1951 op == OP_DELETE_THREAD ? 0 : 1);
1952 if (option (OPTRESOLVE))
1953 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1954 menu->current = menu->oldcurrent;
1955 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1961 if (Context && Context->magic == M_NNTP) {
1962 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1963 ((NNTP_DATA *) Context->data)->group))
1964 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1969 case OP_DISPLAY_ADDRESS:
1973 mutt_display_address (CURHDR->env);
1976 case OP_ENTER_COMMAND:
1978 CurrentMenu = MENU_MAIN;
1979 mutt_enter_command ();
1980 mutt_check_rescore (Context);
1981 if (option (OPTFORCEREDRAWINDEX))
1982 menu->redraw = REDRAW_FULL;
1983 unset_option (OPTFORCEREDRAWINDEX);
1984 unset_option (OPTFORCEREDRAWPAGER);
1987 case OP_EDIT_MESSAGE:
1994 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1996 if (option (OPTPGPAUTODEC)
1997 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1998 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1999 mutt_edit_message (Context, tag ? NULL : CURHDR);
2000 menu->redraw = REDRAW_FULL;
2004 case OP_FORWARD_MESSAGE:
2010 if (option (OPTPGPAUTODEC) &&
2011 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2012 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2013 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2014 menu->redraw = REDRAW_FULL;
2018 case OP_FORGET_PASSPHRASE:
2019 crypt_forget_passphrase ();
2022 case OP_GROUP_REPLY:
2028 if (option (OPTPGPAUTODEC) &&
2029 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2030 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2032 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2033 tag ? NULL : CURHDR);
2034 menu->redraw = REDRAW_FULL;
2043 if (option (OPTPGPAUTODEC) &&
2044 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2045 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2047 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2048 tag ? NULL : CURHDR);
2049 menu->redraw = REDRAW_FULL;
2055 ci_send_message (0, NULL, NULL, Context, NULL);
2056 menu->redraw = REDRAW_FULL;
2060 if (!(WithCrypto & APPLICATION_PGP))
2063 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2064 menu->redraw = REDRAW_FULL;
2068 case OP_EXTRACT_KEYS:
2073 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2074 menu->redraw = REDRAW_FULL;
2078 case OP_CHECK_TRADITIONAL:
2079 if (!(WithCrypto & APPLICATION_PGP))
2083 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2084 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2086 if (menu->menu == MENU_PAGER) {
2087 op = OP_DISPLAY_MESSAGE;
2096 mutt_pipe_message (tag ? NULL : CURHDR);
2097 MAYBE_REDRAW (menu->redraw);
2104 mutt_print_message (tag ? NULL : CURHDR);
2107 case OP_MAIN_READ_THREAD:
2108 case OP_MAIN_READ_SUBTHREAD:
2114 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2116 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2117 op == OP_MAIN_READ_THREAD ? 0 : 1);
2120 if (option (OPTRESOLVE)) {
2121 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2122 mutt_next_thread (CURHDR) :
2123 mutt_next_subthread (CURHDR))) == -1)
2124 menu->current = menu->oldcurrent;
2126 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2130 case OP_RECALL_MESSAGE:
2133 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2134 menu->redraw = REDRAW_FULL;
2144 for (j = 0; j < Context->vcount; j++) {
2145 if (Context->hdrs[Context->v2r[j]]->tagged)
2146 mutt_resend_message (NULL, Context,
2147 Context->hdrs[Context->v2r[j]]);
2151 mutt_resend_message (NULL, Context, CURHDR);
2153 menu->redraw = REDRAW_FULL;
2159 case OP_FORWARD_TO_GROUP:
2162 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2163 Context && Context->msgcount == 0) {
2164 mutt_error (_("There are no messages."));
2167 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2168 safe_strcasecmp (CURHDR->env->followup_to, "poster") ||
2169 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2170 _("Reply by mail as poster prefers?")) !=
2172 if (Context && Context->magic == M_NNTP
2173 && !((NNTP_DATA *) Context->data)->allowed
2174 && query_quadoption (OPT_TOMODERATED,
2176 ("Posting to this group not allowed, may be moderated. Continue?"))
2180 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2183 if (op == OP_FOLLOWUP)
2184 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2185 tag ? NULL : CURHDR);
2187 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2188 tag ? NULL : CURHDR);
2190 menu->redraw = REDRAW_FULL;
2201 if (option (OPTPGPAUTODEC) &&
2202 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2203 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2205 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2206 menu->redraw = REDRAW_FULL;
2209 case OP_SHELL_ESCAPE:
2211 mutt_shell_escape ();
2212 MAYBE_REDRAW (menu->redraw);
2216 case OP_TAG_SUBTHREAD:
2220 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2221 op == OP_TAG_THREAD ? 0 : 1);
2224 if (option (OPTRESOLVE)) {
2225 menu->current = mutt_next_thread (CURHDR);
2227 if (menu->current == -1)
2228 menu->current = menu->oldcurrent;
2230 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2240 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2243 mutt_tag_set_flag (M_DELETE, 0);
2244 mutt_tag_set_flag (M_PURGED, 0);
2245 menu->redraw = REDRAW_INDEX;
2248 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2249 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2250 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2252 menu->redraw = REDRAW_MOTION_RESYNCH;
2255 menu->redraw = REDRAW_CURRENT;
2257 menu->redraw |= REDRAW_STATUS;
2260 case OP_UNDELETE_THREAD:
2261 case OP_UNDELETE_SUBTHREAD:
2267 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2269 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2270 op == OP_UNDELETE_THREAD ? 0 : 1)
2271 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2272 op == OP_UNDELETE_THREAD ? 0 : 1);
2275 if (option (OPTRESOLVE)) {
2276 if (op == OP_UNDELETE_THREAD)
2277 menu->current = mutt_next_thread (CURHDR);
2279 menu->current = mutt_next_subthread (CURHDR);
2281 if (menu->current == -1)
2282 menu->current = menu->oldcurrent;
2284 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2294 menu->redraw = REDRAW_FULL;
2297 case OP_VIEW_ATTACHMENTS:
2300 mutt_view_attachments (CURHDR);
2301 if (CURHDR->attach_del)
2302 Context->changed = 1;
2303 menu->redraw = REDRAW_FULL;
2313 case OP_SIDEBAR_SCROLL_UP:
2314 case OP_SIDEBAR_SCROLL_DOWN:
2315 case OP_SIDEBAR_NEXT:
2316 case OP_SIDEBAR_PREV:
2317 case OP_SIDEBAR_NEXT_NEW:
2318 case OP_SIDEBAR_PREV_NEW:
2319 sidebar_scroll (op, menu->menu);
2322 if (menu->menu == MENU_MAIN)
2323 km_error_key (MENU_MAIN);
2326 if (menu->menu == MENU_PAGER) {
2327 menu->menu = MENU_MAIN;
2328 menu->redraw = REDRAW_FULL;
2330 set_option (OPTWEED); /* turn header weeding back on. */
2339 /* Close all open IMAP connections */
2344 /* Close all open NNTP connections */
2349 mutt_menuDestroy (&menu);
2353 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2360 for (color = ColorIndexList; color; color = color->next)
2361 if (mutt_pattern_exec
2362 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2363 curhdr->pair = color->pair;
2366 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];