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.
13 #include <lib-lib/lib-lib.h>
15 #include <lib-ui/sidebar.h>
16 #include <lib-mx/mx.h>
27 #include "recvattach.h"
31 #include <imap/imap_private.h>
34 #include <nntp/nntp.h>
37 static const char *No_mailbox_is_open = N_("No mailbox is open.");
38 static const char *There_are_no_messages = N_("There are no messages.");
39 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
40 static const char *Function_not_permitted_in_attach_message_mode =
41 N_("Function not permitted in attach-message mode.");
42 static const char *No_visible = N_("No visible messages.");
44 #define CHECK_IN_MAILBOX if (!Context) \
47 mutt_error (_(No_mailbox_is_open)); \
51 #define CHECK_MSGCOUNT if (!Context) \
54 mutt_error(_(No_mailbox_is_open)); \
57 else if (!Context->msgcount) \
60 mutt_error(_(There_are_no_messages)); \
64 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
67 mutt_error(_(No_visible)); \
72 #define CHECK_READONLY if (Context->readonly) \
75 mutt_error(_(Mailbox_is_read_only)); \
79 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
82 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
86 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
87 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
88 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
89 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
91 extern size_t UngetCount;
93 void index_make_entry (char *s, ssize_t l, struct menu_t * menu, int num)
95 format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_INDEX;
96 int edgemsgno, reverse = Sort & SORT_REVERSE;
97 HEADER *h = Context->hdrs[Context->v2r[num]];
100 if (option(OPTARROWCURSOR))
101 flag |= M_FORMAT_ARROWCURSOR;
103 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
104 flag |= M_FORMAT_TREE; /* display the thread tree */
105 if (h->display_subject)
106 flag |= M_FORMAT_FORCESUBJ;
109 if (menu->top + menu->pagelen > menu->max)
110 edgemsgno = Context->v2r[menu->max - 1];
112 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
115 edgemsgno = Context->v2r[menu->top];
117 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
121 /* if no ancestor is visible on current screen, provisionally force
123 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
125 flag |= M_FORMAT_FORCESUBJ;
128 else if (tmp->message->virtual >= 0)
131 if (flag & M_FORMAT_FORCESUBJ) {
132 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
136 /* ...but if a previous sibling is available, don't force it */
137 if (reverse ? tmp->message->msgno >
138 edgemsgno : tmp->message->msgno < edgemsgno)
140 else if (tmp->message->virtual >= 0) {
141 flag &= ~M_FORMAT_FORCESUBJ;
149 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
152 int index_color (int index_no)
154 HEADER *h = Context->hdrs[Context->v2r[index_no]];
159 mutt_set_header_color (Context, h);
163 static int ci_next_undeleted (int msgno)
167 for (i = msgno + 1; i < Context->vcount; i++)
168 if (!Context->hdrs[Context->v2r[i]]->deleted)
173 static int ci_previous_undeleted (int msgno)
177 for (i = msgno - 1; i >= 0; i--)
178 if (!Context->hdrs[Context->v2r[i]]->deleted)
183 /* Return the index of the first new message, or failing that, the first
186 static int ci_first_message (void)
190 if (Context && Context->msgcount) {
191 for (i = 0; i < Context->vcount; i++) {
192 if (!Context->hdrs[Context->v2r[i]]->read &&
193 !Context->hdrs[Context->v2r[i]]->deleted) {
194 if (!Context->hdrs[Context->v2r[i]]->old)
203 /* If Sort is reverse and not threaded, the latest message is first.
204 * If Sort is threaded, the latest message is first iff exactly one
205 * of Sort and SortAux are reverse.
207 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
208 ((Sort & SORT_MASK) == SORT_THREADS &&
209 ((Sort ^ SortAux) & SORT_REVERSE)))
212 return (Context->vcount ? Context->vcount - 1 : 0);
217 /* This should be in mx.c, but it only gets used here. */
218 static int mx_toggle_write (CONTEXT * ctx)
224 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
229 if (ctx->dontwrite) {
231 mutt_message (_("Changes to folder will be written on folder exit."));
235 mutt_message (_("Changes to folder will not be written."));
241 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
242 int oldcount, int index_hint)
244 /* store pointers to the newly added messages */
245 HEADER **save_new = NULL;
248 /* take note of the current message */
250 if (menu->current < Context->vcount)
251 menu->oldcurrent = index_hint;
253 oldcount = 0; /* invalid message number! */
256 /* We are in a limited view. Check if the new message(s) satisfy
257 * the limit criteria. If they do, set their virtual msgno so that
258 * they will be visible in the limited view */
259 if (Context->pattern) {
260 #define THIS_BODY Context->hdrs[j]->content
261 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
262 if (mutt_pattern_exec
263 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
265 Context->hdrs[j]->virtual = Context->vcount;
266 Context->v2r[Context->vcount] = j;
267 Context->hdrs[j]->limited = 1;
270 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
276 /* save the list of new messages */
277 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
278 save_new = p_new(HEADER*, Context->msgcount - oldcount);
279 for (j = oldcount; j < Context->msgcount; j++)
280 save_new[j - oldcount] = Context->hdrs[j];
283 /* if the mailbox was reopened, need to rethread from scratch */
284 mutt_sort_headers (Context, (check == M_REOPENED));
286 /* uncollapse threads with new mail */
287 if ((Sort & SORT_MASK) == SORT_THREADS) {
288 if (check == M_REOPENED) {
291 Context->collapsed = 0;
293 for (h = Context->tree; h; h = h->next) {
294 for (c = h; !c->message; c = c->child);
295 mutt_uncollapse_thread (Context, c->message);
297 mutt_set_virtual (Context);
300 for (j = 0; j < Context->msgcount - oldcount; j++) {
303 for (k = 0; k < Context->msgcount; k++) {
304 HEADER *h = Context->hdrs[k];
306 if (h == save_new[j] && (!Context->pattern || h->limited))
307 mutt_uncollapse_thread (Context, h);
311 mutt_set_virtual (Context);
317 /* restore the current message to the message it was pointing to */
318 for (j = 0; j < Context->vcount; j++) {
319 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
326 if (menu->current < 0)
327 menu->current = ci_first_message ();
330 static void resort_index (MUTTMENU * menu)
333 HEADER *current = CURHDR;
336 mutt_sort_headers (Context, 0);
337 /* Restore the current message */
339 for (i = 0; i < Context->vcount; i++) {
340 if (Context->hdrs[Context->v2r[i]] == current) {
346 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
347 menu->current = mutt_parent_message (Context, current);
349 if (menu->current < 0)
350 menu->current = ci_first_message ();
352 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
355 struct mapping_t IndexHelp[] = {
356 {N_("Quit"), OP_QUIT},
357 {N_("Del"), OP_DELETE},
358 {N_("Undel"), OP_UNDELETE},
359 {N_("Save"), OP_SAVE},
360 {N_("Mail"), OP_MAIL},
361 {N_("Reply"), OP_REPLY},
362 {N_("Group"), OP_GROUP_REPLY},
363 {N_("Help"), OP_HELP},
368 struct mapping_t IndexNewsHelp[] = {
369 {N_("Quit"), OP_QUIT},
370 {N_("Del"), OP_DELETE},
371 {N_("Undel"), OP_UNDELETE},
372 {N_("Save"), OP_SAVE},
373 {N_("Post"), OP_POST},
374 {N_("Followup"), OP_FOLLOWUP},
375 {N_("Catchup"), OP_CATCHUP},
376 {N_("Help"), OP_HELP},
381 /* This function handles the message index window as well as commands returned
382 * from the pager (MENU_PAGER).
384 int mutt_index_menu (void)
386 char buf[LONG_STRING], helpstr[STRING];
389 int done = 0; /* controls when to exit the "event" loop */
391 int tag = 0; /* has the tag-prefix command been pressed? */
396 const char *cp; /* temporary variable. */
397 int index_hint; /* used to restore cursor position */
398 int do_buffy_notify = 1;
399 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
400 int attach_msg = option (OPTATTACHMSG);
402 menu = mutt_new_menu ();
403 menu->menu = MENU_MAIN;
405 menu->pagelen = LINES - 3;
406 menu->make_entry = (void *) index_make_entry;
407 menu->color = index_color;
408 menu->current = ci_first_message ();
409 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
412 && (Context->magic ==
413 M_NNTP)) ? IndexNewsHelp :
418 buffy_check (0); /* force the buffy check after we enter the folder */
419 /* record folder we open to place sidebar indicator properly */
420 if (Context && Context->path)
421 sidebar_set_current (Context->path);
425 tag = 0; /* clear the tag-prefix */
427 menu->max = Context ? Context->vcount : 0;
428 oldcount = Context ? Context->msgcount : 0;
430 /* check if we need to resort the index because just about
431 * any 'op' below could do mutt_enter_command(), either here or
432 * from any new menu launched, and change $sort/$sort_aux
434 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
437 if (option (OPTREDRAWTREE) && Context && Context->msgcount
438 && (Sort & SORT_MASK) == SORT_THREADS) {
439 mutt_draw_tree (Context);
440 menu->redraw |= REDRAW_STATUS;
441 unset_option (OPTREDRAWTREE);
444 if (Context && !attach_msg) {
447 /* check for new mail in the mailbox. If nonzero, then something has
448 * changed about the file (either we got new mail or the file was
449 * modified underneath us.)
452 imap_allow_reopen (Context);
454 index_hint = (Context->vcount && menu->current >= 0
455 && menu->current < Context->vcount) ? CURHDR->index : 0;
457 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
458 if (!Context->path) {
459 /* fatal error occurred */
461 menu->redraw = REDRAW_FULL;
463 set_option (OPTSEARCHINVALID);
465 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
466 update_index (menu, Context, check, oldcount, index_hint);
468 /* notify the user of new mail */
469 if (check == M_REOPENED)
471 ("Mailbox was externally modified. Flags may be wrong."));
472 else if (check == M_NEW_MAIL) {
473 /* on new mail: redraw sidebar */
475 mutt_message (_("New mail in this mailbox."));
480 else if (check == M_FLAGS)
481 mutt_message (_("Mailbox was externally modified."));
483 /* avoid the message being overwritten by buffy */
486 menu->redraw = REDRAW_FULL;
487 menu->max = Context->vcount;
489 set_option (OPTSEARCHINVALID);
494 imap_disallow_reopen (Context);
497 /* check for new mail in the incoming folders */
499 if ((newcount = buffy_check (0)) != oldcount) {
500 menu->redraw |= REDRAW_STATUS;
501 menu->redraw |= REDRAW_SIDEBAR;
503 if (do_buffy_notify) {
504 if (buffy_notify () && MCore.beep_new)
513 if (menu->redraw & REDRAW_SIDEBAR)
515 if (menu->redraw & REDRAW_FULL) {
516 menu_redraw_full (menu);
521 if (menu->menu == MENU_MAIN) {
522 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
523 menu_check_recenter (menu);
525 if (menu->redraw & REDRAW_INDEX) {
526 menu_redraw_index (menu);
527 menu->redraw |= REDRAW_STATUS;
529 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
530 menu_redraw_motion (menu);
531 else if (menu->redraw & REDRAW_CURRENT)
532 menu_redraw_current (menu);
535 if (menu->redraw & REDRAW_STATUS) {
536 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
537 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
538 sidebar_draw_frames();
539 SETCOLOR (MT_COLOR_STATUS);
540 BKGDSET (MT_COLOR_STATUS);
541 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
542 mutt_paddstr (COLS-SW, buf);
543 SETCOLOR (MT_COLOR_NORMAL);
544 BKGDSET (MT_COLOR_NORMAL);
545 sidebar_set_buffystats (Context);
546 menu->redraw &= ~REDRAW_STATUS;
547 if (option (OPTXTERMSETTITLES)) {
548 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermTitle));
549 printf("\033]2;%s\007", buf);
550 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermIcon));
551 printf("\033]1;%s\007", buf);
557 if (menu->current < menu->max)
558 menu->oldcurrent = menu->current;
560 menu->oldcurrent = -1;
562 if (option (OPTARROWCURSOR))
563 move (menu->current - menu->top + menu->offset, 2);
564 else if (option (OPTBRAILLEFRIENDLY))
565 move (menu->current - menu->top + menu->offset, 0);
567 move (menu->current - menu->top + menu->offset, COLS - 1);
570 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
573 mutt_resize_screen ();
574 menu->redraw = REDRAW_FULL;
575 menu->menu = MENU_MAIN;
577 menu->top = 0; /* so we scroll the right amount */
579 * force a real complete redraw. clrtobot() doesn't seem to be able
580 * to handle every case without this.
582 clearok (stdscr, TRUE);
587 op = km_dokey (MENU_MAIN);
590 continue; /* either user abort or timeout */
594 /* special handling for the tag-prefix function */
595 if (op == OP_TAG_PREFIX) {
597 mutt_error (_("No mailbox is open."));
602 if (!Context->tagged) {
603 mutt_error (_("No tagged messages."));
609 /* give visual indication that the next command is a tag- command */
610 mvaddstr (LINES - 1, 0, "tag-");
613 /* get the real command */
614 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
615 /* abort tag sequence */
616 CLEARLINE (LINES - 1);
620 else if (option (OPTAUTOTAG) && Context && Context->tagged)
623 if (op == OP_TAG_PREFIX_COND) {
625 mutt_error (_("No mailbox is open."));
630 if (!Context->tagged) {
633 while (UngetCount > 0) {
635 if (tmp.op == OP_END_COND)
638 mutt_message (_("Nothing to do."));
644 /* give visual indication that the next command is a tag- command */
645 mvaddstr (LINES - 1, 0, "tag-");
648 /* get the real command */
649 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
650 /* abort tag sequence */
651 CLEARLINE (LINES - 1);
659 if (menu->current < menu->max)
660 menu->oldcurrent = menu->current;
662 menu->oldcurrent = -1;
664 mutt_curs_set (1); /* fallback from the pager */
668 unset_option (OPTNEWS); /* for any case */
673 /* ----------------------------------------------------------------------
678 menu_bottom_page (menu);
681 menu_first_entry (menu);
684 menu_middle_page (menu);
690 menu_half_down (menu);
693 menu_next_line (menu);
696 menu_prev_line (menu);
699 menu_next_page (menu);
702 menu_prev_page (menu);
705 menu_last_entry (menu);
708 menu_top_page (menu);
711 menu_current_top (menu);
713 case OP_CURRENT_MIDDLE:
714 menu_current_middle (menu);
716 case OP_CURRENT_BOTTOM:
717 menu_current_bottom (menu);
724 if (Context->magic == M_NNTP) {
727 if (op == OP_GET_MESSAGE) {
729 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
734 string_list_t *ref = CURHDR->env->references;
737 mutt_error (_("Article has no parent reference!"));
741 m_strcpy(buf, sizeof(buf), ref->data);
743 if (!Context->id_hash)
744 Context->id_hash = mutt_make_id_hash (Context);
745 if ((h = hash_find (Context->id_hash, buf))) {
746 if (h->virtual != -1) {
747 menu->current = h->virtual;
748 menu->redraw = REDRAW_MOTION_RESYNCH;
750 else if (h->collapsed) {
751 mutt_uncollapse_thread (Context, h);
752 mutt_set_virtual (Context);
753 menu->current = h->virtual;
754 menu->redraw = REDRAW_MOTION_RESYNCH;
757 mutt_error (_("Message not visible in limited view."));
760 if (nntp_check_msgid (Context, buf) == 0) {
761 h = Context->hdrs[Context->msgcount - 1];
762 mutt_sort_headers (Context, 0);
763 menu->current = h->virtual;
764 menu->redraw = REDRAW_FULL;
767 mutt_error (_("Article %s not found on server"), buf);
772 case OP_GET_CHILDREN:
773 case OP_RECONSTRUCT_THREAD:
775 if (Context->magic == M_NNTP) {
777 int old = CURHDR->index;
779 if (!CURHDR->env->message_id) {
780 mutt_error (_("No Message-ID. Unable to perform operation"));
785 if (!Context->id_hash)
786 Context->id_hash = mutt_make_id_hash (Context);
787 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
789 if (op == OP_RECONSTRUCT_THREAD) {
790 string_list_t *ref = CURHDR->env->references;
793 nntp_check_msgid (Context, ref->data);
794 /* the last msgid in References is the root message */
796 m_strcpy(buf, sizeof(buf), ref->data);
800 mutt_message (_("Check for children of message..."));
802 if (nntp_check_children (Context, buf) == 0) {
803 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
804 h = hash_find (Context->id_hash, buf);
805 /* if the root message was retrieved, move to it */
807 menu->current = h->virtual;
808 else /* try to restore old position */
809 for (i = 0; i < Context->msgcount; i++)
810 if (Context->hdrs[i]->index == old) {
811 menu->current = Context->hdrs[i]->virtual;
812 /* As an added courtesy, recenter the menu
813 * with the current entry at the middle of the screen */
814 menu_check_recenter (menu);
815 menu_current_middle (menu);
818 menu->redraw = REDRAW_FULL;
828 if (isdigit (LastKey))
829 mutt_ungetch (LastKey, 0);
831 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
835 if (!isdigit ((unsigned char) buf[0])) {
836 mutt_error (_("Argument must be a message number."));
842 if (i > 0 && i <= Context->msgcount) {
843 for (j = i - 1; j < Context->msgcount; j++) {
844 if (Context->hdrs[j]->virtual != -1)
847 if (j >= Context->msgcount) {
848 for (j = i - 2; j >= 0; j--) {
849 if (Context->hdrs[j]->virtual != -1)
855 menu->current = Context->hdrs[j]->virtual;
856 if (menu->menu == MENU_PAGER) {
857 op = OP_DISPLAY_MESSAGE;
861 menu->redraw = REDRAW_MOTION;
864 mutt_error (_("That message is not visible."));
867 mutt_error (_("Invalid message number."));
871 /* --------------------------------------------------------------------
872 * `index' specific commands
875 case OP_MAIN_DELETE_PATTERN:
881 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
884 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
885 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
888 case OP_MAIN_FETCH_MAIL:
892 menu->redraw = REDRAW_FULL;
897 mutt_help (MENU_MAIN);
898 menu->redraw = REDRAW_FULL;
901 case OP_MAIN_SHOW_LIMIT:
903 if (!Context->pattern)
904 mutt_message (_("No limit pattern is in effect."));
909 /* i18n: ask for a limit to apply */
910 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
911 mutt_message ("%s", buffer);
919 menu->oldcurrent = (Context->vcount && menu->current >= 0
921 Context->vcount) ? CURHDR->index : -1;
922 if (op == OP_TOGGLE_READ) {
923 char buffer[LONG_STRING];
925 if (m_strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
926 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
927 Context->pattern ? Context->pattern : ".*");
928 set_option (OPTHIDEREAD);
931 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
932 if (m_strncmp (buf, ".*", 2) == 0)
933 snprintf (buf, sizeof (buf), "~A");
934 unset_option (OPTHIDEREAD);
936 p_delete(&Context->pattern);
937 Context->pattern = m_strdup(buf);
939 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
940 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
942 if (menu->oldcurrent >= 0) {
943 /* try to find what used to be the current message */
945 for (i = 0; i < Context->vcount; i++)
946 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
950 if (menu->current < 0)
955 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
956 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
957 mutt_draw_tree (Context);
958 menu->redraw = REDRAW_FULL;
960 if (Context->pattern)
961 mutt_message _("To view all messages, limit to \"all\".");
972 if (query_quadoption2(MCore.quit, _("Quit Madmutt?")) == M_YES) {
975 oldcount = Context ? Context->msgcount : 0;
978 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
981 if (check == M_NEW_MAIL || check == M_REOPENED)
982 update_index (menu, Context, check, oldcount, index_hint);
984 menu->redraw = REDRAW_FULL; /* new mail arrived? */
985 set_option (OPTSEARCHINVALID);
992 clearok (stdscr, TRUE);
993 menu->redraw = REDRAW_FULL;
997 case OP_SEARCH_REVERSE:
999 case OP_SEARCH_OPPOSITE:
1003 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1004 menu->current = menu->oldcurrent;
1006 menu->redraw = REDRAW_MOTION;
1010 case OP_SORT_REVERSE:
1012 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1013 if (Context && Context->msgcount) {
1014 resort_index (menu);
1015 set_option (OPTSEARCHINVALID);
1024 if (tag && !option (OPTAUTOTAG)) {
1025 for (j = 0; j < Context->vcount; j++)
1026 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1027 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1030 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1031 Context->last_tag = CURHDR->tagged ? CURHDR :
1032 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1033 ? NULL : Context->last_tag);
1034 menu->redraw = REDRAW_STATUS;
1035 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1037 menu->redraw |= REDRAW_MOTION_RESYNCH;
1040 menu->redraw |= REDRAW_CURRENT;
1044 case OP_MAIN_TAG_PATTERN:
1048 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1049 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1052 case OP_MAIN_UNDELETE_PATTERN:
1058 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1060 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1062 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1065 case OP_MAIN_UNTAG_PATTERN:
1069 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1070 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1073 /* --------------------------------------------------------------------
1074 * The following operations can be performed inside of the pager.
1077 case OP_MAIN_IMAP_FETCH:
1078 if (Context->magic == M_IMAP)
1079 imap_check_mailbox (Context, &index_hint, 1);
1082 case OP_MAIN_SYNC_FOLDER:
1084 if (Context && !Context->msgcount)
1091 int oldvcount = Context->vcount;
1092 oldcount = Context->msgcount;
1096 /* calculate the number of messages _above_ the cursor,
1097 * so we can keep the cursor on the current message
1099 for (j = 0; j <= menu->current; j++) {
1100 if (Context->hdrs[Context->v2r[j]]->deleted)
1104 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1105 if (Context->vcount != oldvcount)
1106 menu->current -= dcount;
1107 set_option (OPTSEARCHINVALID);
1109 else if (check == M_NEW_MAIL || check == M_REOPENED)
1110 update_index (menu, Context, check, oldcount, index_hint);
1113 * do a sanity check even if mx_sync_mailbox failed.
1116 if (menu->current < 0 || menu->current >= Context->vcount)
1117 menu->current = ci_first_message ();
1120 /* check for a fatal error, or all messages deleted */
1124 /* if we were in the pager, redisplay the message */
1125 if (menu->menu == MENU_PAGER) {
1126 op = OP_DISPLAY_MESSAGE;
1130 menu->redraw = REDRAW_FULL;
1133 case OP_SIDEBAR_OPEN:
1134 case OP_MAIN_CHANGE_FOLDER:
1135 case OP_MAIN_CHANGE_FOLDER_READONLY:
1137 case OP_MAIN_CHANGE_GROUP:
1138 case OP_MAIN_CHANGE_GROUP_READONLY:
1140 if (attach_msg || option (OPTREADONLY) ||
1142 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1144 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1150 cp = _("Open mailbox in read-only mode");
1152 cp = _("Open mailbox");
1156 unset_option (OPTNEWS);
1157 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1158 set_option (OPTNEWS);
1159 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1162 cp = _("Open newsgroup in read-only mode");
1164 cp = _("Open newsgroup");
1165 nntp_buffy (buf, sizeof (buf));
1170 if (Context && Context->path)
1171 m_strcpy(buf, sizeof(buf), Context->path);
1172 if (op != OP_SIDEBAR_OPEN)
1173 buffy_next (buf, sizeof (buf));
1176 if (op == OP_SIDEBAR_OPEN) {
1177 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1179 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1180 if (menu->menu == MENU_PAGER) {
1181 op = OP_DISPLAY_MESSAGE;
1187 CLEARLINE (LINES - 1);
1192 if (option (OPTNEWS)) {
1193 unset_option (OPTNEWS);
1194 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1198 mutt_expand_path (buf, sizeof (buf));
1199 if (mx_get_magic (buf) <= 0) {
1200 mutt_error (_("%s is not a mailbox."), buf);
1203 m_strreplace(&CurrentFolder, buf);
1208 if (Context->cinfo && Context->realpath)
1209 m_strreplace(&LastFolder, Context->realpath);
1211 m_strreplace(&LastFolder, Context->path);
1212 oldcount = Context ? Context->msgcount : 0;
1214 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1215 if (check == M_NEW_MAIL || check == M_REOPENED)
1216 update_index (menu, Context, check, oldcount, index_hint);
1218 set_option (OPTSEARCHINVALID);
1219 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1227 /* Set CurrentMenu to MENU_MAIN before executing any folder
1228 * hooks so that all the index menu functions are available to
1232 CurrentMenu = MENU_MAIN;
1233 mutt_folder_hook (buf);
1235 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1236 menu->current = ci_first_message ();
1240 sidebar_set_current (buf);
1243 /* buffy_check() must be done with mail-reader mode! */
1244 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1246 && (Context->magic ==
1247 M_NNTP)) ? IndexNewsHelp :
1250 mutt_clear_error ();
1251 buffy_check (0); /* force the buffy check after we have changed
1253 menu->redraw = REDRAW_FULL;
1254 set_option (OPTSEARCHINVALID);
1257 case OP_DISPLAY_MESSAGE:
1258 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1263 * toggle the weeding of headers so that a user can press the key
1264 * again while reading the message.
1266 if (op == OP_DISPLAY_HEADERS)
1267 toggle_option (OPTWEED);
1269 unset_option (OPTNEEDRESORT);
1271 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1272 mutt_uncollapse_thread (Context, CURHDR);
1273 mutt_set_virtual (Context);
1274 if (option (OPTUNCOLLAPSEJUMP))
1275 menu->current = mutt_thread_next_unread (Context, CURHDR);
1278 if (option (OPTPGPAUTODEC) &&
1279 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1280 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1282 if ((op = mutt_display_message (CURHDR)) == -1) {
1283 unset_option (OPTNEEDRESORT);
1287 menu->menu = MENU_PAGER;
1288 menu->oldcurrent = menu->current;
1294 if (menu->menu == MENU_MAIN && attach_msg) {
1299 if ((menu->menu == MENU_MAIN)
1300 && (query_quadoption2(MCore.quit,
1301 _("Exit Madmutt without saving?")) == M_YES))
1304 mx_fastclose_mailbox (Context);
1316 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1317 /* if we were in the pager, redisplay the message */
1318 if (menu->menu == MENU_PAGER) {
1319 op = OP_DISPLAY_MESSAGE;
1323 menu->redraw = REDRAW_CURRENT;
1326 case OP_MAIN_BREAK_THREAD:
1332 if ((Sort & SORT_MASK) != SORT_THREADS)
1333 mutt_error (_("Threading is not enabled."));
1337 HEADER *oldcur = CURHDR;
1339 mutt_break_thread (CURHDR);
1340 mutt_sort_headers (Context, 1);
1341 menu->current = oldcur->virtual;
1344 Context->changed = 1;
1345 mutt_message _("Thread broken");
1347 if (menu->menu == MENU_PAGER) {
1348 op = OP_DISPLAY_MESSAGE;
1352 menu->redraw |= REDRAW_INDEX;
1356 case OP_MAIN_LINK_THREADS:
1362 if ((Sort & SORT_MASK) != SORT_THREADS)
1363 mutt_error (_("Threading is not enabled."));
1365 else if (!CURHDR->env->message_id)
1366 mutt_error (_("No Message-ID: header available to link thread"));
1368 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1369 mutt_error (_("First, please tag a message to be linked here"));
1372 HEADER *oldcur = CURHDR;
1374 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1376 mutt_sort_headers (Context, 1);
1377 menu->current = oldcur->virtual;
1379 Context->changed = 1;
1380 mutt_message _("Threads linked");
1383 mutt_error (_("No thread linked"));
1386 if (menu->menu == MENU_PAGER) {
1387 op = OP_DISPLAY_MESSAGE;
1391 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1394 case OP_MAIN_NEXT_UNDELETED:
1398 if (menu->current >= Context->vcount - 1) {
1399 if (menu->menu == MENU_MAIN)
1400 mutt_error (_("You are on the last message."));
1404 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1405 menu->current = menu->oldcurrent;
1406 if (menu->menu == MENU_MAIN)
1407 mutt_error (_("No undeleted messages."));
1409 else if (menu->menu == MENU_PAGER) {
1410 op = OP_DISPLAY_MESSAGE;
1414 menu->redraw = REDRAW_MOTION;
1421 if (menu->current >= Context->vcount - 1) {
1422 if (menu->menu == MENU_MAIN)
1423 mutt_error (_("You are on the last message."));
1428 if (menu->menu == MENU_PAGER) {
1429 op = OP_DISPLAY_MESSAGE;
1433 menu->redraw = REDRAW_MOTION;
1436 case OP_MAIN_PREV_UNDELETED:
1440 if (menu->current < 1) {
1441 mutt_error (_("You are on the first message."));
1445 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1446 menu->current = menu->oldcurrent;
1447 if (menu->menu == MENU_MAIN)
1448 mutt_error (_("No undeleted messages."));
1450 else if (menu->menu == MENU_PAGER) {
1451 op = OP_DISPLAY_MESSAGE;
1455 menu->redraw = REDRAW_MOTION;
1462 if (menu->current < 1) {
1463 if (menu->menu == MENU_MAIN)
1464 mutt_error (_("You are on the first message."));
1469 if (menu->menu == MENU_PAGER) {
1470 op = OP_DISPLAY_MESSAGE;
1474 menu->redraw = REDRAW_MOTION;
1477 case OP_DECRYPT_COPY:
1478 case OP_DECRYPT_SAVE:
1479 case OP_COPY_MESSAGE:
1481 case OP_DECODE_COPY:
1482 case OP_DECODE_SAVE:
1485 if (mutt_save_message (tag ? NULL : CURHDR,
1486 (op == OP_DECRYPT_SAVE) ||
1487 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1488 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1489 (op == OP_DECRYPT_SAVE)
1490 || (op == OP_DECRYPT_COPY)
1491 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1498 menu->redraw |= REDRAW_INDEX;
1499 else if (option (OPTRESOLVE)) {
1500 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1501 menu->current = menu->oldcurrent;
1502 menu->redraw |= REDRAW_CURRENT;
1505 menu->redraw |= REDRAW_MOTION_RESYNCH;
1508 menu->redraw |= REDRAW_CURRENT;
1512 case OP_MAIN_NEXT_NEW:
1513 case OP_MAIN_NEXT_UNREAD:
1514 case OP_MAIN_PREV_NEW:
1515 case OP_MAIN_PREV_UNREAD:
1516 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1517 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1520 int first_unread = -1;
1528 for (j = 0; j != Context->vcount; j++) {
1529 #define CURHDRi Context->hdrs[Context->v2r[i]]
1530 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1531 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1533 if (i > Context->vcount - 1) {
1534 mutt_message _("Search wrapped to top.");
1542 mutt_message _("Search wrapped to bottom.");
1544 i = Context->vcount - 1;
1548 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1549 if (UNREAD (CURHDRi) && first_unread == -1)
1551 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1554 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1555 if (first_unread == -1)
1557 if ((!CURHDRi->old) && first_new == -1)
1561 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1564 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1565 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1566 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1571 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1572 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1573 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1575 menu->current = first_new;
1576 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1577 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1578 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1579 && first_unread != -1)
1580 menu->current = first_unread;
1582 if (menu->current == -1) {
1583 menu->current = menu->oldcurrent;
1584 mutt_error ("%s%s.",
1585 (op == OP_MAIN_NEXT_NEW
1587 OP_MAIN_PREV_NEW) ? _("No new messages") :
1588 _("No unread messages"),
1589 Context->pattern ? _(" in this limited view") : "");
1591 else if (menu->menu == MENU_PAGER) {
1592 op = OP_DISPLAY_MESSAGE;
1596 menu->redraw = REDRAW_MOTION;
1599 case OP_FLAG_MESSAGE:
1605 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1608 for (j = 0; j < Context->vcount; j++) {
1609 if (Context->hdrs[Context->v2r[j]]->tagged)
1610 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1611 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1614 menu->redraw |= REDRAW_INDEX;
1617 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1618 if (option (OPTRESOLVE)) {
1619 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1620 menu->current = menu->oldcurrent;
1621 menu->redraw = REDRAW_CURRENT;
1624 menu->redraw = REDRAW_MOTION_RESYNCH;
1627 menu->redraw = REDRAW_CURRENT;
1629 menu->redraw |= REDRAW_STATUS;
1638 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1641 for (j = 0; j < Context->vcount; j++) {
1642 if (Context->hdrs[Context->v2r[j]]->tagged) {
1643 if (Context->hdrs[Context->v2r[j]]->read ||
1644 Context->hdrs[Context->v2r[j]]->old)
1645 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1648 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1652 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1655 if (CURHDR->read || CURHDR->old)
1656 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1658 mutt_set_flag (Context, CURHDR, M_READ, 1);
1660 if (option (OPTRESOLVE)) {
1661 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1662 menu->current = menu->oldcurrent;
1663 menu->redraw = REDRAW_CURRENT;
1666 menu->redraw = REDRAW_MOTION_RESYNCH;
1669 menu->redraw = REDRAW_CURRENT;
1670 menu->redraw |= REDRAW_STATUS;
1674 case OP_TOGGLE_WRITE:
1677 if (mx_toggle_write (Context) == 0)
1678 menu->redraw |= REDRAW_STATUS;
1681 case OP_MAIN_NEXT_THREAD:
1682 case OP_MAIN_NEXT_SUBTHREAD:
1683 case OP_MAIN_PREV_THREAD:
1684 case OP_MAIN_PREV_SUBTHREAD:
1689 case OP_MAIN_NEXT_THREAD:
1690 menu->current = mutt_next_thread (CURHDR);
1693 case OP_MAIN_NEXT_SUBTHREAD:
1694 menu->current = mutt_next_subthread (CURHDR);
1697 case OP_MAIN_PREV_THREAD:
1698 menu->current = mutt_previous_thread (CURHDR);
1701 case OP_MAIN_PREV_SUBTHREAD:
1702 menu->current = mutt_previous_subthread (CURHDR);
1706 if (menu->current < 0) {
1707 menu->current = menu->oldcurrent;
1708 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1709 mutt_error (_("No more threads."));
1712 mutt_error (_("You are on the first thread."));
1714 else if (menu->menu == MENU_PAGER) {
1715 op = OP_DISPLAY_MESSAGE;
1719 menu->redraw = REDRAW_MOTION;
1722 case OP_MAIN_PARENT_MESSAGE:
1727 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1728 menu->current = menu->oldcurrent;
1730 else if (menu->menu == MENU_PAGER) {
1731 op = OP_DISPLAY_MESSAGE;
1735 menu->redraw = REDRAW_MOTION;
1738 case OP_MAIN_SET_FLAG:
1739 case OP_MAIN_CLEAR_FLAG:
1745 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0) {
1746 menu->redraw = REDRAW_STATUS;
1748 menu->redraw |= REDRAW_INDEX;
1749 else if (option (OPTRESOLVE)) {
1750 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1751 menu->current = menu->oldcurrent;
1752 menu->redraw |= REDRAW_CURRENT;
1755 menu->redraw |= REDRAW_MOTION_RESYNCH;
1758 menu->redraw |= REDRAW_CURRENT;
1762 case OP_MAIN_COLLAPSE_THREAD:
1766 if ((Sort & SORT_MASK) != SORT_THREADS) {
1767 mutt_error (_("Threading is not enabled."));
1772 if (CURHDR->collapsed) {
1773 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1774 mutt_set_virtual (Context);
1775 if (option (OPTUNCOLLAPSEJUMP))
1776 menu->current = mutt_thread_next_unread (Context, CURHDR);
1778 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1779 menu->current = mutt_collapse_thread (Context, CURHDR);
1780 mutt_set_virtual (Context);
1783 mutt_error (_("Thread contains unread messages."));
1788 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1792 case OP_MAIN_COLLAPSE_ALL:
1796 if ((Sort & SORT_MASK) != SORT_THREADS) {
1797 mutt_error (_("Threading is not enabled."));
1804 THREAD *thread, *top;
1807 if (CURHDR->collapsed)
1808 final = mutt_uncollapse_thread (Context, CURHDR);
1809 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1810 final = mutt_collapse_thread (Context, CURHDR);
1812 final = CURHDR->virtual;
1814 base = Context->hdrs[Context->v2r[final]];
1816 top = Context->tree;
1817 Context->collapsed = !Context->collapsed;
1818 while ((thread = top) != NULL) {
1819 while (!thread->message)
1820 thread = thread->child;
1821 h = thread->message;
1823 if (h->collapsed != Context->collapsed) {
1825 mutt_uncollapse_thread (Context, h);
1826 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1827 mutt_collapse_thread (Context, h);
1832 mutt_set_virtual (Context);
1833 for (j = 0; j < Context->vcount; j++) {
1834 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1840 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1844 /* --------------------------------------------------------------------
1845 * These functions are invoked directly from the internal-pager
1848 case OP_BOUNCE_MESSAGE:
1853 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1856 case OP_CREATE_ALIAS:
1858 mutt_create_alias (Context
1859 && Context->vcount ? CURHDR->env : NULL, NULL);
1860 MAYBE_REDRAW (menu->redraw);
1861 menu->redraw |= REDRAW_CURRENT;
1866 mutt_query_menu (NULL, 0);
1867 MAYBE_REDRAW (menu->redraw);
1870 case OP_PURGE_MESSAGE:
1877 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1880 mutt_tag_set_flag (M_DELETE, 1);
1881 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1882 if (option (OPTDELETEUNTAG))
1883 mutt_tag_set_flag (M_TAG, 0);
1884 menu->redraw = REDRAW_INDEX;
1887 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1888 mutt_set_flag (Context, CURHDR, M_PURGED,
1889 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1890 if (option (OPTDELETEUNTAG))
1891 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1892 if (option (OPTRESOLVE)) {
1893 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1894 menu->current = menu->oldcurrent;
1895 menu->redraw = REDRAW_CURRENT;
1897 else if (menu->menu == MENU_PAGER) {
1898 op = OP_DISPLAY_MESSAGE;
1902 menu->redraw |= REDRAW_MOTION_RESYNCH;
1905 menu->redraw = REDRAW_CURRENT;
1907 menu->redraw |= REDRAW_STATUS;
1910 case OP_DELETE_THREAD:
1911 case OP_DELETE_SUBTHREAD:
1917 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1919 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1920 op == OP_DELETE_THREAD ? 0 : 1);
1923 if (option (OPTDELETEUNTAG))
1924 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1925 op == OP_DELETE_THREAD ? 0 : 1);
1926 if (option (OPTRESOLVE))
1927 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1928 menu->current = menu->oldcurrent;
1929 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1935 if (Context && Context->magic == M_NNTP) {
1936 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1937 ((NNTP_DATA *) Context->data)->group))
1938 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1943 case OP_DISPLAY_ADDRESS:
1947 mutt_display_address (CURHDR->env);
1950 case OP_ENTER_COMMAND:
1952 CurrentMenu = MENU_MAIN;
1953 mutt_enter_command ();
1954 mutt_check_rescore (Context);
1955 if (option (OPTFORCEREDRAWINDEX))
1956 menu->redraw = REDRAW_FULL;
1957 unset_option (OPTFORCEREDRAWINDEX);
1958 unset_option (OPTFORCEREDRAWPAGER);
1961 case OP_EDIT_MESSAGE:
1968 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1970 if (option (OPTPGPAUTODEC)
1971 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1972 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1973 mutt_edit_message (Context, tag ? NULL : CURHDR);
1974 menu->redraw = REDRAW_FULL;
1978 case OP_FORWARD_MESSAGE:
1984 if (option (OPTPGPAUTODEC) &&
1985 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1986 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1987 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
1988 menu->redraw = REDRAW_FULL;
1991 case OP_GROUP_REPLY:
1997 if (option (OPTPGPAUTODEC) &&
1998 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1999 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2001 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2002 tag ? NULL : CURHDR);
2003 menu->redraw = REDRAW_FULL;
2012 if (option (OPTPGPAUTODEC) &&
2013 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2014 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2016 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2017 tag ? NULL : CURHDR);
2018 menu->redraw = REDRAW_FULL;
2024 ci_send_message (0, NULL, NULL, Context, NULL);
2025 menu->redraw = REDRAW_FULL;
2028 case OP_EXTRACT_KEYS:
2031 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2032 menu->redraw = REDRAW_FULL;
2036 case OP_CHECK_TRADITIONAL:
2039 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2040 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2042 if (menu->menu == MENU_PAGER) {
2043 op = OP_DISPLAY_MESSAGE;
2052 mutt_pipe_message (tag ? NULL : CURHDR);
2053 /* in an IMAP folder index with imap_peek=no, piping could change
2054 * * new or old messages status to read. Redraw what's needed.
2056 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2057 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2059 MAYBE_REDRAW (menu->redraw);
2066 mutt_print_message (tag ? NULL : CURHDR);
2067 /* in an IMAP folder index with imap_peek=no, piping could change
2068 * * new or old messages status to read. Redraw what's needed.
2070 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2071 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2075 case OP_MAIN_READ_THREAD:
2076 case OP_MAIN_READ_SUBTHREAD:
2082 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2084 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2085 op == OP_MAIN_READ_THREAD ? 0 : 1);
2088 if (option (OPTRESOLVE)) {
2089 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2090 mutt_next_thread (CURHDR) :
2091 mutt_next_subthread (CURHDR))) == -1)
2092 menu->current = menu->oldcurrent;
2094 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2098 case OP_RECALL_MESSAGE:
2101 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2102 menu->redraw = REDRAW_FULL;
2112 for (j = 0; j < Context->vcount; j++) {
2113 if (Context->hdrs[Context->v2r[j]]->tagged)
2114 mutt_resend_message (NULL, Context,
2115 Context->hdrs[Context->v2r[j]]);
2119 mutt_resend_message (NULL, Context, CURHDR);
2121 menu->redraw = REDRAW_FULL;
2127 case OP_FORWARD_TO_GROUP:
2130 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2131 Context && Context->msgcount == 0) {
2132 mutt_error (_("There are no messages."));
2135 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2136 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2137 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2138 _("Reply by mail as poster prefers?")) !=
2140 if (Context && Context->magic == M_NNTP
2141 && !((NNTP_DATA *) Context->data)->allowed
2142 && query_quadoption (OPT_TOMODERATED,
2144 ("Posting to this group not allowed, may be moderated. Continue?"))
2148 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2151 if (op == OP_FOLLOWUP)
2152 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2153 tag ? NULL : CURHDR);
2155 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2156 tag ? NULL : CURHDR);
2158 menu->redraw = REDRAW_FULL;
2169 if (option (OPTPGPAUTODEC) &&
2170 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2171 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2173 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2174 menu->redraw = REDRAW_FULL;
2177 case OP_SHELL_ESCAPE:
2179 mutt_shell_escape ();
2180 MAYBE_REDRAW (menu->redraw);
2184 case OP_TAG_SUBTHREAD:
2188 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2189 op == OP_TAG_THREAD ? 0 : 1);
2192 if (option (OPTRESOLVE)) {
2193 menu->current = mutt_next_thread (CURHDR);
2195 if (menu->current == -1)
2196 menu->current = menu->oldcurrent;
2198 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2208 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2211 mutt_tag_set_flag (M_DELETE, 0);
2212 mutt_tag_set_flag (M_PURGED, 0);
2213 menu->redraw = REDRAW_INDEX;
2216 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2217 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2218 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2220 menu->redraw = REDRAW_MOTION_RESYNCH;
2223 menu->redraw = REDRAW_CURRENT;
2225 menu->redraw |= REDRAW_STATUS;
2228 case OP_UNDELETE_THREAD:
2229 case OP_UNDELETE_SUBTHREAD:
2235 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2237 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2238 op == OP_UNDELETE_THREAD ? 0 : 1)
2239 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2240 op == OP_UNDELETE_THREAD ? 0 : 1);
2243 if (option (OPTRESOLVE)) {
2244 if (op == OP_UNDELETE_THREAD)
2245 menu->current = mutt_next_thread (CURHDR);
2247 menu->current = mutt_next_subthread (CURHDR);
2249 if (menu->current == -1)
2250 menu->current = menu->oldcurrent;
2252 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2261 if (option (OPTFORCEBUFFYCHECK))
2264 menu->redraw = REDRAW_FULL;
2267 case OP_VIEW_ATTACHMENTS:
2270 mutt_view_attachments (CURHDR);
2271 if (CURHDR->attach_del)
2272 Context->changed = 1;
2273 menu->redraw = REDRAW_FULL;
2283 case OP_SIDEBAR_SCROLL_UP:
2284 case OP_SIDEBAR_SCROLL_DOWN:
2285 case OP_SIDEBAR_NEXT:
2286 case OP_SIDEBAR_PREV:
2287 case OP_SIDEBAR_NEXT_NEW:
2288 case OP_SIDEBAR_PREV_NEW:
2289 sidebar_scroll (op);
2292 if (menu->menu == MENU_MAIN)
2293 km_error_key (MENU_MAIN);
2296 if (menu->menu == MENU_PAGER) {
2297 menu->menu = MENU_MAIN;
2298 menu->redraw = REDRAW_FULL;
2306 /* Close all open IMAP connections */
2309 /* Close all open NNTP connections */
2314 mutt_menuDestroy (&menu);
2318 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2325 for (color = ColorIndexList; color; color = color->next)
2326 if (mutt_pattern_exec
2327 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2328 curhdr->pair = color->pair;
2331 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];