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 mutt_paddstr (COLS, buf);
561 SETCOLOR (MT_COLOR_NORMAL);
562 sidebar_set_buffystats (Context);
563 menu->redraw &= ~REDRAW_STATUS;
564 if (option (OPTXTERMSETTITLES)) {
565 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
566 mutt_xterm_set_title (buf);
567 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
568 mutt_xterm_set_icon (buf);
573 if (menu->current < menu->max)
574 menu->oldcurrent = menu->current;
576 menu->oldcurrent = -1;
578 if (option (OPTARROWCURSOR))
579 move (menu->current - menu->top + menu->offset, 2);
580 else if (option (OPTBRAILLEFRIENDLY))
581 move (menu->current - menu->top + menu->offset, 0);
583 move (menu->current - menu->top + menu->offset, COLS - 1);
586 op = km_dokey (MENU_MAIN);
588 debug_print (4, ("Got op %d\n", op));
590 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
593 mutt_resize_screen ();
594 menu->redraw = REDRAW_FULL;
595 menu->menu = MENU_MAIN;
597 menu->top = 0; /* so we scroll the right amount */
599 * force a real complete redraw. clrtobot() doesn't seem to be able
600 * to handle every case without this.
602 clearok (stdscr, TRUE);
608 continue; /* either user abort or timeout */
612 /* special handling for the tag-prefix function */
613 if (op == OP_TAG_PREFIX) {
615 mutt_error (_("No mailbox is open."));
620 if (!Context->tagged) {
621 mutt_error (_("No tagged messages."));
627 /* give visual indication that the next command is a tag- command */
628 mvaddstr (LINES - 1, 0, "tag-");
631 /* get the real command */
632 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
633 /* abort tag sequence */
634 CLEARLINE (LINES - 1);
638 else if (option (OPTAUTOTAG) && Context && Context->tagged)
641 if (op == OP_TAG_PREFIX_COND) {
643 mutt_error (_("No mailbox is open."));
648 if (!Context->tagged) {
651 while (UngetCount > 0) {
653 if (tmp.op == OP_END_COND)
656 mutt_message (_("Nothing to do."));
662 /* give visual indication that the next command is a tag- command */
663 mvaddstr (LINES - 1, 0, "tag-");
666 /* get the real command */
667 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
668 /* abort tag sequence */
669 CLEARLINE (LINES - 1);
677 if (menu->current < menu->max)
678 menu->oldcurrent = menu->current;
680 menu->oldcurrent = -1;
682 mutt_curs_set (1); /* fallback from the pager */
686 unset_option (OPTNEWS); /* for any case */
691 /* ----------------------------------------------------------------------
696 menu_bottom_page (menu);
699 menu_first_entry (menu);
702 menu_middle_page (menu);
708 menu_half_down (menu);
711 menu_next_line (menu);
714 menu_prev_line (menu);
717 menu_next_page (menu);
720 menu_prev_page (menu);
723 menu_last_entry (menu);
726 menu_top_page (menu);
729 menu_current_top (menu);
731 case OP_CURRENT_MIDDLE:
732 menu_current_middle (menu);
734 case OP_CURRENT_BOTTOM:
735 menu_current_bottom (menu);
742 if (Context->magic == M_NNTP) {
745 if (op == OP_GET_MESSAGE) {
747 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0)
752 LIST *ref = CURHDR->env->references;
755 mutt_error (_("Article has no parent reference!"));
759 strfcpy (buf, ref->data, sizeof (buf));
761 if (!Context->id_hash)
762 Context->id_hash = mutt_make_id_hash (Context);
763 if ((h = hash_find (Context->id_hash, buf))) {
764 if (h->virtual != -1) {
765 menu->current = h->virtual;
766 menu->redraw = REDRAW_MOTION_RESYNCH;
768 else if (h->collapsed) {
769 mutt_uncollapse_thread (Context, h);
770 mutt_set_virtual (Context);
771 menu->current = h->virtual;
772 menu->redraw = REDRAW_MOTION_RESYNCH;
775 mutt_error (_("Message not visible in limited view."));
778 if (nntp_check_msgid (Context, buf) == 0) {
779 h = Context->hdrs[Context->msgcount - 1];
780 mutt_sort_headers (Context, 0);
781 menu->current = h->virtual;
782 menu->redraw = REDRAW_FULL;
785 mutt_error (_("Article %s not found on server"), buf);
790 case OP_GET_CHILDREN:
791 case OP_RECONSTRUCT_THREAD:
793 if (Context->magic == M_NNTP) {
795 int old = CURHDR->index, i;
797 if (!CURHDR->env->message_id) {
798 mutt_error (_("No Message-Id. Unable to perform operation"));
803 if (!Context->id_hash)
804 Context->id_hash = mutt_make_id_hash (Context);
805 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
807 if (op == OP_RECONSTRUCT_THREAD) {
808 LIST *ref = CURHDR->env->references;
811 nntp_check_msgid (Context, ref->data);
812 /* the last msgid in References is the root message */
814 strfcpy (buf, ref->data, sizeof (buf));
818 mutt_message (_("Check for children of message..."));
820 if (nntp_check_children (Context, buf) == 0) {
821 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
822 h = hash_find (Context->id_hash, buf);
823 /* if the root message was retrieved, move to it */
825 menu->current = h->virtual;
826 else /* try to restore old position */
827 for (i = 0; i < Context->msgcount; i++)
828 if (Context->hdrs[i]->index == old) {
829 menu->current = Context->hdrs[i]->virtual;
830 /* As an added courtesy, recenter the menu
831 * with the current entry at the middle of the screen */
832 menu_check_recenter (menu);
833 menu_current_middle (menu);
836 menu->redraw = REDRAW_FULL;
846 if (isdigit (LastKey))
847 mutt_ungetch (LastKey, 0);
849 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
853 if (!isdigit ((unsigned char) buf[0])) {
854 mutt_error (_("Argument must be a message number."));
860 if (i > 0 && i <= Context->msgcount) {
861 for (j = i - 1; j < Context->msgcount; j++) {
862 if (Context->hdrs[j]->virtual != -1)
865 if (j >= Context->msgcount) {
866 for (j = i - 2; j >= 0; j--) {
867 if (Context->hdrs[j]->virtual != -1)
873 menu->current = Context->hdrs[j]->virtual;
874 if (menu->menu == MENU_PAGER) {
875 op = OP_DISPLAY_MESSAGE;
879 menu->redraw = REDRAW_MOTION;
882 mutt_error (_("That message is not visible."));
885 mutt_error (_("Invalid message number."));
889 /* --------------------------------------------------------------------
890 * `index' specific commands
893 case OP_MAIN_DELETE_PATTERN:
899 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
902 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
903 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
907 case OP_MAIN_FETCH_MAIL:
911 menu->redraw = REDRAW_FULL;
917 mutt_help (MENU_MAIN);
918 menu->redraw = REDRAW_FULL;
921 case OP_MAIN_SHOW_LIMIT:
923 if (!Context->pattern)
924 mutt_message (_("No limit pattern is in effect."));
929 /* i18n: ask for a limit to apply */
930 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
931 mutt_message ("%s", buf);
939 menu->oldcurrent = (Context->vcount && menu->current >= 0
941 Context->vcount) ? CURHDR->index : -1;
942 if (op == OP_TOGGLE_READ) {
943 char buf[LONG_STRING];
945 if (!Context->pattern
946 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
947 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
948 Context->pattern ? Context->pattern : ".*");
949 set_option (OPTHIDEREAD);
952 strfcpy (buf, Context->pattern + 8, sizeof (buf));
953 if (!*buf || strncmp (buf, ".*", 2) == 0)
954 snprintf (buf, sizeof (buf), "~A");
955 unset_option (OPTHIDEREAD);
957 FREE (&Context->pattern);
958 Context->pattern = safe_strdup (buf);
960 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
961 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
963 if (menu->oldcurrent >= 0) {
964 /* try to find what used to be the current message */
966 for (i = 0; i < Context->vcount; i++)
967 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
971 if (menu->current < 0)
976 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
977 if ((Sort & SORT_MASK) == SORT_THREADS)
978 mutt_draw_tree (Context);
979 menu->redraw = REDRAW_FULL;
991 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
994 oldcount = Context ? Context->msgcount : 0;
997 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1000 if (check == M_NEW_MAIL || check == M_REOPENED)
1001 update_index (menu, Context, check, oldcount, index_hint);
1003 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1004 set_option (OPTSEARCHINVALID);
1011 clearok (stdscr, TRUE);
1012 menu->redraw = REDRAW_FULL;
1016 case OP_SEARCH_REVERSE:
1017 case OP_SEARCH_NEXT:
1018 case OP_SEARCH_OPPOSITE:
1022 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1023 menu->current = menu->oldcurrent;
1025 menu->redraw = REDRAW_MOTION;
1029 case OP_SORT_REVERSE:
1031 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1032 if (Context && Context->msgcount) {
1033 resort_index (menu);
1034 set_option (OPTSEARCHINVALID);
1043 if (tag && !option (OPTAUTOTAG)) {
1044 for (j = 0; j < Context->vcount; j++)
1045 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1046 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1049 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1050 Context->last_tag = CURHDR->tagged ? CURHDR :
1051 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1052 ? NULL : Context->last_tag);
1053 menu->redraw = REDRAW_STATUS;
1054 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1056 menu->redraw |= REDRAW_MOTION_RESYNCH;
1059 menu->redraw |= REDRAW_CURRENT;
1063 case OP_MAIN_TAG_PATTERN:
1067 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1068 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1071 case OP_MAIN_UNDELETE_PATTERN:
1077 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1079 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1081 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1084 case OP_MAIN_UNTAG_PATTERN:
1088 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1089 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1092 /* --------------------------------------------------------------------
1093 * The following operations can be performed inside of the pager.
1097 case OP_MAIN_IMAP_FETCH:
1098 if (Context->magic == M_IMAP)
1099 imap_check_mailbox (Context, &index_hint, 1);
1103 case OP_MAIN_SYNC_FOLDER:
1105 if (Context && !Context->msgcount)
1112 int oldvcount = Context->vcount;
1113 int oldcount = Context->msgcount;
1117 /* calculate the number of messages _above_ the cursor,
1118 * so we can keep the cursor on the current message
1120 for (j = 0; j <= menu->current; j++) {
1121 if (Context->hdrs[Context->v2r[j]]->deleted)
1125 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1126 if (Context->vcount != oldvcount)
1127 menu->current -= dcount;
1128 set_option (OPTSEARCHINVALID);
1130 else if (check == M_NEW_MAIL || check == M_REOPENED)
1131 update_index (menu, Context, check, oldcount, index_hint);
1134 * do a sanity check even if mx_sync_mailbox failed.
1137 if (menu->current < 0 || menu->current >= Context->vcount)
1138 menu->current = ci_first_message ();
1141 /* check for a fatal error, or all messages deleted */
1145 /* if we were in the pager, redisplay the message */
1146 if (menu->menu == MENU_PAGER) {
1147 op = OP_DISPLAY_MESSAGE;
1151 menu->redraw = REDRAW_FULL;
1154 case OP_SIDEBAR_OPEN:
1155 case OP_MAIN_CHANGE_FOLDER:
1156 case OP_MAIN_CHANGE_FOLDER_READONLY:
1158 case OP_MAIN_CHANGE_GROUP:
1159 case OP_MAIN_CHANGE_GROUP_READONLY:
1161 if (attach_msg || option (OPTREADONLY) ||
1163 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1165 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1171 cp = _("Open mailbox in read-only mode");
1173 cp = _("Open mailbox");
1177 unset_option (OPTNEWS);
1178 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1179 set_option (OPTNEWS);
1180 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1183 cp = _("Open newsgroup in read-only mode");
1185 cp = _("Open newsgroup");
1191 if (Context && Context->path)
1192 strncpy (buf, Context->path, sizeof (buf));
1193 if (op != OP_SIDEBAR_OPEN)
1194 buffy_next (buf, sizeof (buf));
1197 if (op == OP_SIDEBAR_OPEN) {
1198 strncpy (buf, NONULL(sidebar_get_current ()), sizeof (buf));
1200 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1204 CLEARLINE (LINES - 1);
1209 if (option (OPTNEWS)) {
1210 unset_option (OPTNEWS);
1211 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1215 mutt_expand_path (buf, sizeof (buf));
1216 if (mx_get_magic (buf) <= 0) {
1217 mutt_error (_("%s is not a mailbox."), buf);
1220 str_replace (&CurrentFolder, buf);
1225 #ifdef USE_COMPRESSED
1226 if (Context->compressinfo && Context->realpath)
1227 str_replace (&LastFolder, Context->realpath);
1231 str_replace (&LastFolder, Context->path);
1232 oldcount = Context ? Context->msgcount : 0;
1234 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1235 if (check == M_NEW_MAIL || check == M_REOPENED)
1236 update_index (menu, Context, check, oldcount, index_hint);
1238 set_option (OPTSEARCHINVALID);
1239 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1247 /* Set CurrentMenu to MENU_MAIN before executing any folder
1248 * hooks so that all the index menu functions are available to
1252 CurrentMenu = MENU_MAIN;
1253 mutt_folder_hook (buf);
1255 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1256 menu->current = ci_first_message ();
1260 sidebar_set_current (buf);
1263 /* buffy_check() must be done with mail-reader mode! */
1264 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1266 && (Context->magic ==
1267 M_NNTP)) ? IndexNewsHelp :
1270 mutt_clear_error ();
1271 buffy_check (1); /* force the buffy check after we have changed
1273 menu->redraw = REDRAW_FULL;
1274 set_option (OPTSEARCHINVALID);
1277 case OP_DISPLAY_MESSAGE:
1278 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1283 * toggle the weeding of headers so that a user can press the key
1284 * again while reading the message.
1286 if (op == OP_DISPLAY_HEADERS)
1287 toggle_option (OPTWEED);
1289 unset_option (OPTNEEDRESORT);
1291 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1292 mutt_uncollapse_thread (Context, CURHDR);
1293 mutt_set_virtual (Context);
1294 if (option (OPTUNCOLLAPSEJUMP))
1295 menu->current = mutt_thread_next_unread (Context, CURHDR);
1298 if (option (OPTPGPAUTODEC) &&
1299 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1300 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1301 if ((op = mutt_display_message (CURHDR)) == -1) {
1302 unset_option (OPTNEEDRESORT);
1306 if ((op = mutt_display_message (CURHDR)) == -1) {
1307 unset_option (OPTNEEDRESORT);
1311 menu->menu = MENU_PAGER;
1312 menu->oldcurrent = menu->current;
1318 if (menu->menu == MENU_MAIN && attach_msg) {
1323 if ((menu->menu == MENU_MAIN)
1324 && (query_quadoption (OPT_QUIT,
1325 _("Exit Mutt-ng without saving?")) == M_YES))
1328 mx_fastclose_mailbox (Context);
1340 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1341 /* if we were in the pager, redisplay the message */
1342 if (menu->menu == MENU_PAGER) {
1343 op = OP_DISPLAY_MESSAGE;
1347 menu->redraw = REDRAW_CURRENT;
1350 case OP_MAIN_BREAK_THREAD:
1356 if ((Sort & SORT_MASK) != SORT_THREADS)
1357 mutt_error (_("Threading is not enabled."));
1361 HEADER *oldcur = CURHDR;
1363 mutt_break_thread (CURHDR);
1364 mutt_sort_headers (Context, 1);
1365 menu->current = oldcur->virtual;
1368 Context->changed = 1;
1369 mutt_message _("Thread broken");
1371 if (menu->menu == MENU_PAGER) {
1372 op = OP_DISPLAY_MESSAGE;
1376 menu->redraw |= REDRAW_INDEX;
1380 case OP_MAIN_LINK_THREADS:
1386 if ((Sort & SORT_MASK) != SORT_THREADS)
1387 mutt_error (_("Threading is not enabled."));
1389 else if (!CURHDR->env->message_id)
1390 mutt_error (_("No Message-ID: header available to link thread"));
1392 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1393 mutt_error (_("First, please tag a message to be linked here"));
1396 HEADER *oldcur = CURHDR;
1398 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1400 mutt_sort_headers (Context, 1);
1401 menu->current = oldcur->virtual;
1403 Context->changed = 1;
1404 mutt_message _("Threads linked");
1407 mutt_error (_("No thread linked"));
1410 if (menu->menu == MENU_PAGER) {
1411 op = OP_DISPLAY_MESSAGE;
1415 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1418 case OP_MAIN_NEXT_UNDELETED:
1422 if (menu->current >= Context->vcount - 1) {
1423 if (menu->menu == MENU_MAIN)
1424 mutt_error (_("You are on the last message."));
1428 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1429 menu->current = menu->oldcurrent;
1430 if (menu->menu == MENU_MAIN)
1431 mutt_error (_("No undeleted messages."));
1433 else if (menu->menu == MENU_PAGER) {
1434 op = OP_DISPLAY_MESSAGE;
1438 menu->redraw = REDRAW_MOTION;
1445 if (menu->current >= Context->vcount - 1) {
1446 if (menu->menu == MENU_MAIN)
1447 mutt_error (_("You are on the last message."));
1452 if (menu->menu == MENU_PAGER) {
1453 op = OP_DISPLAY_MESSAGE;
1457 menu->redraw = REDRAW_MOTION;
1460 case OP_MAIN_PREV_UNDELETED:
1464 if (menu->current < 1) {
1465 mutt_error (_("You are on the first message."));
1469 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1470 menu->current = menu->oldcurrent;
1471 if (menu->menu == MENU_MAIN)
1472 mutt_error (_("No undeleted messages."));
1474 else if (menu->menu == MENU_PAGER) {
1475 op = OP_DISPLAY_MESSAGE;
1479 menu->redraw = REDRAW_MOTION;
1486 if (menu->current < 1) {
1487 if (menu->menu == MENU_MAIN)
1488 mutt_error (_("You are on the first message."));
1493 if (menu->menu == MENU_PAGER) {
1494 op = OP_DISPLAY_MESSAGE;
1498 menu->redraw = REDRAW_MOTION;
1501 case OP_DECRYPT_COPY:
1502 case OP_DECRYPT_SAVE:
1506 case OP_COPY_MESSAGE:
1508 case OP_DECODE_COPY:
1509 case OP_DECODE_SAVE:
1512 if (mutt_save_message (tag ? NULL : CURHDR,
1513 (op == OP_DECRYPT_SAVE) ||
1514 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1515 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1516 (op == OP_DECRYPT_SAVE)
1517 || (op == OP_DECRYPT_COPY)
1518 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1525 menu->redraw |= REDRAW_INDEX;
1526 else if (option (OPTRESOLVE)) {
1527 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1528 menu->current = menu->oldcurrent;
1529 menu->redraw |= REDRAW_CURRENT;
1532 menu->redraw |= REDRAW_MOTION_RESYNCH;
1535 menu->redraw |= REDRAW_CURRENT;
1539 case OP_MAIN_NEXT_NEW:
1540 case OP_MAIN_NEXT_UNREAD:
1541 case OP_MAIN_PREV_NEW:
1542 case OP_MAIN_PREV_UNREAD:
1543 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1544 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1547 int first_unread = -1;
1555 for (j = 0; j != Context->vcount; j++) {
1556 #define CURHDRi Context->hdrs[Context->v2r[i]]
1557 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1558 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1560 if (i > Context->vcount - 1) {
1561 mutt_message _("Search wrapped to top.");
1569 mutt_message _("Search wrapped to bottom.");
1571 i = Context->vcount - 1;
1575 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1576 if (UNREAD (CURHDRi) && first_unread == -1)
1578 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1581 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1582 if (first_unread == -1)
1584 if ((!CURHDRi->old) && first_new == -1)
1588 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1591 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1592 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1593 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1598 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1599 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1600 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1602 menu->current = first_new;
1603 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1604 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1605 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1606 && first_unread != -1)
1607 menu->current = first_unread;
1609 if (menu->current == -1) {
1610 menu->current = menu->oldcurrent;
1611 mutt_error ("%s%s.",
1612 (op == OP_MAIN_NEXT_NEW
1614 OP_MAIN_PREV_NEW) ? _("No new messages") :
1615 _("No unread messages"),
1616 Context->pattern ? _(" in this limited view") : "");
1618 else if (menu->menu == MENU_PAGER) {
1619 op = OP_DISPLAY_MESSAGE;
1623 menu->redraw = REDRAW_MOTION;
1626 case OP_FLAG_MESSAGE:
1632 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1635 for (j = 0; j < Context->vcount; j++) {
1636 if (Context->hdrs[Context->v2r[j]]->tagged)
1637 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1638 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1641 menu->redraw |= REDRAW_INDEX;
1644 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1645 if (option (OPTRESOLVE)) {
1646 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1647 menu->current = menu->oldcurrent;
1648 menu->redraw = REDRAW_CURRENT;
1651 menu->redraw = REDRAW_MOTION_RESYNCH;
1654 menu->redraw = REDRAW_CURRENT;
1656 menu->redraw |= REDRAW_STATUS;
1665 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1668 for (j = 0; j < Context->vcount; j++) {
1669 if (Context->hdrs[Context->v2r[j]]->tagged) {
1670 if (Context->hdrs[Context->v2r[j]]->read ||
1671 Context->hdrs[Context->v2r[j]]->old)
1672 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1675 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1679 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1682 if (CURHDR->read || CURHDR->old)
1683 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1685 mutt_set_flag (Context, CURHDR, M_READ, 1);
1687 if (option (OPTRESOLVE)) {
1688 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1689 menu->current = menu->oldcurrent;
1690 menu->redraw = REDRAW_CURRENT;
1693 menu->redraw = REDRAW_MOTION_RESYNCH;
1696 menu->redraw = REDRAW_CURRENT;
1697 menu->redraw |= REDRAW_STATUS;
1701 case OP_TOGGLE_WRITE:
1704 if (mx_toggle_write (Context) == 0)
1705 menu->redraw |= REDRAW_STATUS;
1708 case OP_MAIN_NEXT_THREAD:
1709 case OP_MAIN_NEXT_SUBTHREAD:
1710 case OP_MAIN_PREV_THREAD:
1711 case OP_MAIN_PREV_SUBTHREAD:
1716 case OP_MAIN_NEXT_THREAD:
1717 menu->current = mutt_next_thread (CURHDR);
1720 case OP_MAIN_NEXT_SUBTHREAD:
1721 menu->current = mutt_next_subthread (CURHDR);
1724 case OP_MAIN_PREV_THREAD:
1725 menu->current = mutt_previous_thread (CURHDR);
1728 case OP_MAIN_PREV_SUBTHREAD:
1729 menu->current = mutt_previous_subthread (CURHDR);
1733 if (menu->current < 0) {
1734 menu->current = menu->oldcurrent;
1735 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1736 mutt_error (_("No more threads."));
1739 mutt_error (_("You are on the first thread."));
1741 else if (menu->menu == MENU_PAGER) {
1742 op = OP_DISPLAY_MESSAGE;
1746 menu->redraw = REDRAW_MOTION;
1749 case OP_MAIN_PARENT_MESSAGE:
1754 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1755 menu->current = menu->oldcurrent;
1757 else if (menu->menu == MENU_PAGER) {
1758 op = OP_DISPLAY_MESSAGE;
1762 menu->redraw = REDRAW_MOTION;
1765 case OP_MAIN_SET_FLAG:
1766 case OP_MAIN_CLEAR_FLAG:
1772 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1774 menu->redraw = REDRAW_STATUS;
1776 menu->redraw |= REDRAW_INDEX;
1777 else if (option (OPTRESOLVE)) {
1778 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1779 menu->current = menu->oldcurrent;
1780 menu->redraw |= REDRAW_CURRENT;
1783 menu->redraw |= REDRAW_MOTION_RESYNCH;
1786 menu->redraw |= REDRAW_CURRENT;
1790 case OP_MAIN_COLLAPSE_THREAD:
1794 if ((Sort & SORT_MASK) != SORT_THREADS) {
1795 mutt_error (_("Threading is not enabled."));
1800 if (CURHDR->collapsed) {
1801 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1802 mutt_set_virtual (Context);
1803 if (option (OPTUNCOLLAPSEJUMP))
1804 menu->current = mutt_thread_next_unread (Context, CURHDR);
1806 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1807 menu->current = mutt_collapse_thread (Context, CURHDR);
1808 mutt_set_virtual (Context);
1811 mutt_error (_("Thread contains unread messages."));
1816 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1820 case OP_MAIN_COLLAPSE_ALL:
1824 if ((Sort & SORT_MASK) != SORT_THREADS) {
1825 mutt_error (_("Threading is not enabled."));
1832 THREAD *thread, *top;
1835 if (CURHDR->collapsed)
1836 final = mutt_uncollapse_thread (Context, CURHDR);
1837 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1838 final = mutt_collapse_thread (Context, CURHDR);
1840 final = CURHDR->virtual;
1842 base = Context->hdrs[Context->v2r[final]];
1844 top = Context->tree;
1845 Context->collapsed = !Context->collapsed;
1846 while ((thread = top) != NULL) {
1847 while (!thread->message)
1848 thread = thread->child;
1849 h = thread->message;
1851 if (h->collapsed != Context->collapsed) {
1853 mutt_uncollapse_thread (Context, h);
1854 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1855 mutt_collapse_thread (Context, h);
1860 mutt_set_virtual (Context);
1861 for (j = 0; j < Context->vcount; j++) {
1862 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1868 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1872 /* --------------------------------------------------------------------
1873 * These functions are invoked directly from the internal-pager
1876 case OP_BOUNCE_MESSAGE:
1881 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1884 case OP_CREATE_ALIAS:
1886 mutt_create_alias (Context
1887 && Context->vcount ? CURHDR->env : NULL, NULL);
1888 MAYBE_REDRAW (menu->redraw);
1889 menu->redraw |= REDRAW_CURRENT;
1894 mutt_query_menu (NULL, 0);
1895 MAYBE_REDRAW (menu->redraw);
1898 case OP_PURGE_MESSAGE:
1905 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1908 mutt_tag_set_flag (M_DELETE, 1);
1909 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1910 if (option (OPTDELETEUNTAG))
1911 mutt_tag_set_flag (M_TAG, 0);
1912 menu->redraw = REDRAW_INDEX;
1915 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1916 mutt_set_flag (Context, CURHDR, M_PURGED,
1917 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1918 if (option (OPTDELETEUNTAG))
1919 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1920 if (option (OPTRESOLVE)) {
1921 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1922 menu->current = menu->oldcurrent;
1923 menu->redraw = REDRAW_CURRENT;
1925 else if (menu->menu == MENU_PAGER) {
1926 op = OP_DISPLAY_MESSAGE;
1930 menu->redraw |= REDRAW_MOTION_RESYNCH;
1933 menu->redraw = REDRAW_CURRENT;
1935 menu->redraw |= REDRAW_STATUS;
1938 case OP_DELETE_THREAD:
1939 case OP_DELETE_SUBTHREAD:
1945 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1947 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1948 op == OP_DELETE_THREAD ? 0 : 1);
1951 if (option (OPTDELETEUNTAG))
1952 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1953 op == OP_DELETE_THREAD ? 0 : 1);
1954 if (option (OPTRESOLVE))
1955 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1956 menu->current = menu->oldcurrent;
1957 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1963 if (Context && Context->magic == M_NNTP) {
1964 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1965 ((NNTP_DATA *) Context->data)->group))
1966 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1971 case OP_DISPLAY_ADDRESS:
1975 mutt_display_address (CURHDR->env);
1978 case OP_ENTER_COMMAND:
1980 CurrentMenu = MENU_MAIN;
1981 mutt_enter_command ();
1982 mutt_check_rescore (Context);
1983 if (option (OPTFORCEREDRAWINDEX))
1984 menu->redraw = REDRAW_FULL;
1985 unset_option (OPTFORCEREDRAWINDEX);
1986 unset_option (OPTFORCEREDRAWPAGER);
1989 case OP_EDIT_MESSAGE:
1996 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1998 if (option (OPTPGPAUTODEC)
1999 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2000 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2001 mutt_edit_message (Context, tag ? NULL : CURHDR);
2002 menu->redraw = REDRAW_FULL;
2006 case OP_FORWARD_MESSAGE:
2012 if (option (OPTPGPAUTODEC) &&
2013 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2014 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2015 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2016 menu->redraw = REDRAW_FULL;
2020 case OP_FORGET_PASSPHRASE:
2021 crypt_forget_passphrase ();
2024 case OP_GROUP_REPLY:
2030 if (option (OPTPGPAUTODEC) &&
2031 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2032 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2034 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2035 tag ? NULL : CURHDR);
2036 menu->redraw = REDRAW_FULL;
2045 if (option (OPTPGPAUTODEC) &&
2046 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2047 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2049 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2050 tag ? NULL : CURHDR);
2051 menu->redraw = REDRAW_FULL;
2057 ci_send_message (0, NULL, NULL, Context, NULL);
2058 menu->redraw = REDRAW_FULL;
2062 if (!(WithCrypto & APPLICATION_PGP))
2065 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2066 menu->redraw = REDRAW_FULL;
2070 case OP_EXTRACT_KEYS:
2075 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2076 menu->redraw = REDRAW_FULL;
2080 case OP_CHECK_TRADITIONAL:
2081 if (!(WithCrypto & APPLICATION_PGP))
2085 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2086 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2088 if (menu->menu == MENU_PAGER) {
2089 op = OP_DISPLAY_MESSAGE;
2098 mutt_pipe_message (tag ? NULL : CURHDR);
2099 MAYBE_REDRAW (menu->redraw);
2106 mutt_print_message (tag ? NULL : CURHDR);
2109 case OP_MAIN_READ_THREAD:
2110 case OP_MAIN_READ_SUBTHREAD:
2116 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2118 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2119 op == OP_MAIN_READ_THREAD ? 0 : 1);
2122 if (option (OPTRESOLVE)) {
2123 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2124 mutt_next_thread (CURHDR) :
2125 mutt_next_subthread (CURHDR))) == -1)
2126 menu->current = menu->oldcurrent;
2128 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2132 case OP_RECALL_MESSAGE:
2135 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2136 menu->redraw = REDRAW_FULL;
2146 for (j = 0; j < Context->vcount; j++) {
2147 if (Context->hdrs[Context->v2r[j]]->tagged)
2148 mutt_resend_message (NULL, Context,
2149 Context->hdrs[Context->v2r[j]]);
2153 mutt_resend_message (NULL, Context, CURHDR);
2155 menu->redraw = REDRAW_FULL;
2161 case OP_FORWARD_TO_GROUP:
2164 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2165 Context && Context->msgcount == 0) {
2166 mutt_error (_("There are no messages."));
2169 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2170 safe_strcasecmp (CURHDR->env->followup_to, "poster") ||
2171 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2172 _("Reply by mail as poster prefers?")) !=
2174 if (Context && Context->magic == M_NNTP
2175 && !((NNTP_DATA *) Context->data)->allowed
2176 && query_quadoption (OPT_TOMODERATED,
2178 ("Posting to this group not allowed, may be moderated. Continue?"))
2182 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2185 if (op == OP_FOLLOWUP)
2186 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2187 tag ? NULL : CURHDR);
2189 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2190 tag ? NULL : CURHDR);
2192 menu->redraw = REDRAW_FULL;
2203 if (option (OPTPGPAUTODEC) &&
2204 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2205 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2207 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2208 menu->redraw = REDRAW_FULL;
2211 case OP_SHELL_ESCAPE:
2213 mutt_shell_escape ();
2214 MAYBE_REDRAW (menu->redraw);
2218 case OP_TAG_SUBTHREAD:
2222 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2223 op == OP_TAG_THREAD ? 0 : 1);
2226 if (option (OPTRESOLVE)) {
2227 menu->current = mutt_next_thread (CURHDR);
2229 if (menu->current == -1)
2230 menu->current = menu->oldcurrent;
2232 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2242 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2245 mutt_tag_set_flag (M_DELETE, 0);
2246 mutt_tag_set_flag (M_PURGED, 0);
2247 menu->redraw = REDRAW_INDEX;
2250 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2251 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2252 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2254 menu->redraw = REDRAW_MOTION_RESYNCH;
2257 menu->redraw = REDRAW_CURRENT;
2259 menu->redraw |= REDRAW_STATUS;
2262 case OP_UNDELETE_THREAD:
2263 case OP_UNDELETE_SUBTHREAD:
2269 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2271 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2272 op == OP_UNDELETE_THREAD ? 0 : 1)
2273 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2274 op == OP_UNDELETE_THREAD ? 0 : 1);
2277 if (option (OPTRESOLVE)) {
2278 if (op == OP_UNDELETE_THREAD)
2279 menu->current = mutt_next_thread (CURHDR);
2281 menu->current = mutt_next_subthread (CURHDR);
2283 if (menu->current == -1)
2284 menu->current = menu->oldcurrent;
2286 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2296 menu->redraw = REDRAW_FULL;
2299 case OP_VIEW_ATTACHMENTS:
2302 mutt_view_attachments (CURHDR);
2303 if (CURHDR->attach_del)
2304 Context->changed = 1;
2305 menu->redraw = REDRAW_FULL;
2315 case OP_SIDEBAR_SCROLL_UP:
2316 case OP_SIDEBAR_SCROLL_DOWN:
2317 case OP_SIDEBAR_NEXT:
2318 case OP_SIDEBAR_PREV:
2319 case OP_SIDEBAR_NEXT_NEW:
2320 case OP_SIDEBAR_PREV_NEW:
2321 sidebar_scroll (op, menu->menu);
2324 if (menu->menu == MENU_MAIN)
2325 km_error_key (MENU_MAIN);
2328 if (menu->menu == MENU_PAGER) {
2329 menu->menu = MENU_MAIN;
2330 menu->redraw = REDRAW_FULL;
2332 set_option (OPTWEED); /* turn header weeding back on. */
2341 /* Close all open IMAP connections */
2346 /* Close all open NNTP connections */
2351 mutt_menuDestroy (&menu);
2355 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2362 for (color = ColorIndexList; color; color = color->next)
2363 if (mutt_pattern_exec
2364 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2365 curhdr->pair = color->pair;
2368 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];