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"
32 #include <imap/imap_private.h>
35 #include <nntp/nntp.h>
38 static const char *No_mailbox_is_open = N_("No mailbox is open.");
39 static const char *There_are_no_messages = N_("There are no messages.");
40 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
41 static const char *Function_not_permitted_in_attach_message_mode =
42 N_("Function not permitted in attach-message mode.");
43 static const char *No_visible = N_("No visible messages.");
45 #define CHECK_IN_MAILBOX if (!Context) \
48 mutt_error (_(No_mailbox_is_open)); \
52 #define CHECK_MSGCOUNT if (!Context) \
55 mutt_error(_(No_mailbox_is_open)); \
58 else if (!Context->msgcount) \
61 mutt_error(_(There_are_no_messages)); \
65 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
68 mutt_error(_(No_visible)); \
73 #define CHECK_READONLY if (Context->readonly) \
76 mutt_error(_(Mailbox_is_read_only)); \
80 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
83 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
87 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
88 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
89 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
90 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
92 extern size_t UngetCount;
94 void index_make_entry (char *s, ssize_t l, struct menu_t * menu, int num)
96 format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_INDEX;
97 int edgemsgno, reverse = Sort & SORT_REVERSE;
98 HEADER *h = Context->hdrs[Context->v2r[num]];
101 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
102 flag |= M_FORMAT_TREE; /* display the thread tree */
103 if (h->display_subject)
104 flag |= M_FORMAT_FORCESUBJ;
107 if (menu->top + menu->pagelen > menu->max)
108 edgemsgno = Context->v2r[menu->max - 1];
110 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
113 edgemsgno = Context->v2r[menu->top];
115 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
119 /* if no ancestor is visible on current screen, provisionally force
121 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
123 flag |= M_FORMAT_FORCESUBJ;
126 else if (tmp->message->virtual >= 0)
129 if (flag & M_FORMAT_FORCESUBJ) {
130 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
134 /* ...but if a previous sibling is available, don't force it */
135 if (reverse ? tmp->message->msgno >
136 edgemsgno : tmp->message->msgno < edgemsgno)
138 else if (tmp->message->virtual >= 0) {
139 flag &= ~M_FORMAT_FORCESUBJ;
147 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
150 int index_color (int index_no)
152 HEADER *h = Context->hdrs[Context->v2r[index_no]];
157 mutt_set_header_color (Context, h);
161 static int ci_next_undeleted (int msgno)
165 for (i = msgno + 1; i < Context->vcount; i++)
166 if (!Context->hdrs[Context->v2r[i]]->deleted)
171 static int ci_previous_undeleted (int msgno)
175 for (i = msgno - 1; i >= 0; i--)
176 if (!Context->hdrs[Context->v2r[i]]->deleted)
181 /* Return the index of the first new message, or failing that, the first
184 static int ci_first_message (void)
188 if (Context && Context->msgcount) {
189 for (i = 0; i < Context->vcount; i++) {
190 if (!Context->hdrs[Context->v2r[i]]->read &&
191 !Context->hdrs[Context->v2r[i]]->deleted) {
192 if (!Context->hdrs[Context->v2r[i]]->old)
201 /* If Sort is reverse and not threaded, the latest message is first.
202 * If Sort is threaded, the latest message is first iff exactly one
203 * of Sort and SortAux are reverse.
205 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
206 ((Sort & SORT_MASK) == SORT_THREADS &&
207 ((Sort ^ SortAux) & SORT_REVERSE)))
210 return (Context->vcount ? Context->vcount - 1 : 0);
215 /* This should be in mx.c, but it only gets used here. */
216 static int mx_toggle_write (CONTEXT * ctx)
222 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
227 if (ctx->dontwrite) {
229 mutt_message (_("Changes to folder will be written on folder exit."));
233 mutt_message (_("Changes to folder will not be written."));
239 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
240 int oldcount, int index_hint)
242 /* store pointers to the newly added messages */
243 HEADER **save_new = NULL;
246 /* take note of the current message */
248 if (menu->current < Context->vcount)
249 menu->oldcurrent = index_hint;
251 oldcount = 0; /* invalid message number! */
254 /* We are in a limited view. Check if the new message(s) satisfy
255 * the limit criteria. If they do, set their virtual msgno so that
256 * they will be visible in the limited view */
257 if (Context->pattern) {
258 #define THIS_BODY Context->hdrs[j]->content
259 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
260 if (mutt_pattern_exec
261 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
263 Context->hdrs[j]->virtual = Context->vcount;
264 Context->v2r[Context->vcount] = j;
265 Context->hdrs[j]->limited = 1;
268 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
274 /* save the list of new messages */
275 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
276 save_new = p_new(HEADER*, Context->msgcount - oldcount);
277 for (j = oldcount; j < Context->msgcount; j++)
278 save_new[j - oldcount] = Context->hdrs[j];
281 /* if the mailbox was reopened, need to rethread from scratch */
282 mutt_sort_headers (Context, (check == M_REOPENED));
284 /* uncollapse threads with new mail */
285 if ((Sort & SORT_MASK) == SORT_THREADS) {
286 if (check == M_REOPENED) {
289 Context->collapsed = 0;
291 for (h = Context->tree; h; h = h->next) {
292 for (c = h; !c->message; c = c->child);
293 mutt_uncollapse_thread (Context, c->message);
295 mutt_set_virtual (Context);
298 for (j = 0; j < Context->msgcount - oldcount; j++) {
301 for (k = 0; k < Context->msgcount; k++) {
302 HEADER *h = Context->hdrs[k];
304 if (h == save_new[j] && (!Context->pattern || h->limited))
305 mutt_uncollapse_thread (Context, h);
309 mutt_set_virtual (Context);
315 /* restore the current message to the message it was pointing to */
316 for (j = 0; j < Context->vcount; j++) {
317 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
324 if (menu->current < 0)
325 menu->current = ci_first_message ();
328 static void resort_index (MUTTMENU * menu)
331 HEADER *current = CURHDR;
334 mutt_sort_headers (Context, 0);
335 /* Restore the current message */
337 for (i = 0; i < Context->vcount; i++) {
338 if (Context->hdrs[Context->v2r[i]] == current) {
344 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
345 menu->current = mutt_parent_message (Context, current);
347 if (menu->current < 0)
348 menu->current = ci_first_message ();
350 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
353 struct mapping_t IndexHelp[] = {
354 {N_("Quit"), OP_QUIT},
355 {N_("Del"), OP_DELETE},
356 {N_("Undel"), OP_UNDELETE},
357 {N_("Save"), OP_SAVE},
358 {N_("Mail"), OP_MAIL},
359 {N_("Reply"), OP_REPLY},
360 {N_("Group"), OP_GROUP_REPLY},
361 {N_("Help"), OP_HELP},
366 struct mapping_t IndexNewsHelp[] = {
367 {N_("Quit"), OP_QUIT},
368 {N_("Del"), OP_DELETE},
369 {N_("Undel"), OP_UNDELETE},
370 {N_("Save"), OP_SAVE},
371 {N_("Post"), OP_POST},
372 {N_("Followup"), OP_FOLLOWUP},
373 {N_("Catchup"), OP_CATCHUP},
374 {N_("Help"), OP_HELP},
379 /* This function handles the message index window as well as commands returned
380 * from the pager (MENU_PAGER).
382 int mutt_index_menu (void)
384 char buf[LONG_STRING], helpstr[STRING];
387 int done = 0; /* controls when to exit the "event" loop */
389 int tag = 0; /* has the tag-prefix command been pressed? */
394 const char *cp; /* temporary variable. */
395 int index_hint; /* used to restore cursor position */
396 int do_buffy_notify = 1;
397 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
398 int attach_msg = option (OPTATTACHMSG);
400 menu = mutt_new_menu ();
401 menu->menu = MENU_MAIN;
403 menu->pagelen = LINES - 3;
404 menu->make_entry = (void *) index_make_entry;
405 menu->color = index_color;
406 menu->current = ci_first_message ();
407 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
410 && (Context->magic ==
411 M_NNTP)) ? IndexNewsHelp :
416 buffy_check (0); /* force the buffy check after we enter the folder */
417 /* record folder we open to place sidebar indicator properly */
418 if (Context && Context->path)
419 sidebar_set_current (Context->path);
423 tag = 0; /* clear the tag-prefix */
425 menu->max = Context ? Context->vcount : 0;
426 oldcount = Context ? Context->msgcount : 0;
428 /* check if we need to resort the index because just about
429 * any 'op' below could do mutt_enter_command(), either here or
430 * from any new menu launched, and change $sort/$sort_aux
432 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
435 if (option (OPTREDRAWTREE) && Context && Context->msgcount
436 && (Sort & SORT_MASK) == SORT_THREADS) {
437 mutt_draw_tree (Context);
438 menu->redraw |= REDRAW_STATUS;
439 unset_option (OPTREDRAWTREE);
442 if (Context && !attach_msg) {
445 /* check for new mail in the mailbox. If nonzero, then something has
446 * changed about the file (either we got new mail or the file was
447 * modified underneath us.)
450 imap_allow_reopen (Context);
452 index_hint = (Context->vcount && menu->current >= 0
453 && menu->current < Context->vcount) ? CURHDR->index : 0;
455 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
456 if (!Context->path) {
457 /* fatal error occurred */
459 menu->redraw = REDRAW_FULL;
461 set_option (OPTSEARCHINVALID);
463 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
464 update_index (menu, Context, check, oldcount, index_hint);
466 /* notify the user of new mail */
467 if (check == M_REOPENED)
469 ("Mailbox was externally modified. Flags may be wrong."));
470 else if (check == M_NEW_MAIL) {
471 /* on new mail: redraw sidebar */
473 mutt_message (_("New mail in this mailbox."));
475 if (mod_core.beep_new)
478 else if (check == M_FLAGS)
479 mutt_message (_("Mailbox was externally modified."));
481 /* avoid the message being overwritten by buffy */
484 menu->redraw = REDRAW_FULL;
485 menu->max = Context->vcount;
487 set_option (OPTSEARCHINVALID);
492 imap_disallow_reopen (Context);
495 /* check for new mail in the incoming folders */
497 if ((newcount = buffy_check (0)) != oldcount) {
498 menu->redraw |= REDRAW_STATUS;
499 menu->redraw |= REDRAW_SIDEBAR;
501 if (do_buffy_notify) {
502 if (buffy_notify () && mod_core.beep_new)
511 if (menu->redraw & REDRAW_SIDEBAR)
513 if (menu->redraw & REDRAW_FULL) {
514 menu_redraw_full (menu);
519 if (menu->menu == MENU_MAIN) {
520 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
521 menu_check_recenter (menu);
523 if (menu->redraw & REDRAW_INDEX) {
524 menu_redraw_index (menu);
525 menu->redraw |= REDRAW_STATUS;
527 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
528 menu_redraw_motion (menu);
529 else if (menu->redraw & REDRAW_CURRENT)
530 menu_redraw_current (menu);
533 if (menu->redraw & REDRAW_STATUS) {
534 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
535 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
536 sidebar_draw_frames();
537 SETCOLOR (MT_COLOR_STATUS);
538 BKGDSET (MT_COLOR_STATUS);
539 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
540 mutt_paddstr (COLS-SW, buf);
541 SETCOLOR (MT_COLOR_NORMAL);
542 BKGDSET (MT_COLOR_NORMAL);
543 sidebar_set_buffystats (Context);
544 menu->redraw &= ~REDRAW_STATUS;
545 if (option (OPTXTERMSETTITLES)) {
546 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermTitle));
547 printf("\033]2;%s\007", buf);
548 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermIcon));
549 printf("\033]1;%s\007", buf);
555 if (menu->current < menu->max)
556 menu->oldcurrent = menu->current;
558 menu->oldcurrent = -1;
560 if (option (OPTBRAILLEFRIENDLY))
561 move (menu->current - menu->top + menu->offset, 0);
563 move (menu->current - menu->top + menu->offset, COLS - 1);
566 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
569 mutt_resize_screen ();
570 menu->redraw = REDRAW_FULL;
571 menu->menu = MENU_MAIN;
573 menu->top = 0; /* so we scroll the right amount */
575 * force a real complete redraw. clrtobot() doesn't seem to be able
576 * to handle every case without this.
578 clearok (stdscr, TRUE);
583 op = km_dokey (MENU_MAIN);
586 continue; /* either user abort or timeout */
590 /* special handling for the tag-prefix function */
591 if (op == OP_TAG_PREFIX) {
593 mutt_error (_("No mailbox is open."));
598 if (!Context->tagged) {
599 mutt_error (_("No tagged messages."));
605 /* give visual indication that the next command is a tag- command */
606 mvaddstr (LINES - 1, 0, "tag-");
609 /* get the real command */
610 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
611 /* abort tag sequence */
612 CLEARLINE (LINES - 1);
616 else if (option (OPTAUTOTAG) && Context && Context->tagged)
619 if (op == OP_TAG_PREFIX_COND) {
621 mutt_error (_("No mailbox is open."));
626 if (!Context->tagged) {
629 while (UngetCount > 0) {
631 if (tmp.op == OP_END_COND)
634 mutt_message (_("Nothing to do."));
640 /* give visual indication that the next command is a tag- command */
641 mvaddstr (LINES - 1, 0, "tag-");
644 /* get the real command */
645 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
646 /* abort tag sequence */
647 CLEARLINE (LINES - 1);
655 if (menu->current < menu->max)
656 menu->oldcurrent = menu->current;
658 menu->oldcurrent = -1;
660 mutt_curs_set (1); /* fallback from the pager */
664 unset_option (OPTNEWS); /* for any case */
669 /* ----------------------------------------------------------------------
674 menu_bottom_page (menu);
677 menu_first_entry (menu);
680 menu_middle_page (menu);
686 menu_half_down (menu);
689 menu_next_line (menu);
692 menu_prev_line (menu);
695 menu_next_page (menu);
698 menu_prev_page (menu);
701 menu_last_entry (menu);
704 menu_top_page (menu);
707 menu_current_top (menu);
709 case OP_CURRENT_MIDDLE:
710 menu_current_middle (menu);
712 case OP_CURRENT_BOTTOM:
713 menu_current_bottom (menu);
720 if (Context->magic == M_NNTP) {
723 if (op == OP_GET_MESSAGE) {
725 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
730 string_list_t *ref = CURHDR->env->references;
733 mutt_error (_("Article has no parent reference!"));
737 m_strcpy(buf, sizeof(buf), ref->data);
739 if (!Context->id_hash)
740 Context->id_hash = mutt_make_id_hash (Context);
741 if ((h = hash_find (Context->id_hash, buf))) {
742 if (h->virtual != -1) {
743 menu->current = h->virtual;
744 menu->redraw = REDRAW_MOTION_RESYNCH;
746 else if (h->collapsed) {
747 mutt_uncollapse_thread (Context, h);
748 mutt_set_virtual (Context);
749 menu->current = h->virtual;
750 menu->redraw = REDRAW_MOTION_RESYNCH;
753 mutt_error (_("Message not visible in limited view."));
756 if (nntp_check_msgid (Context, buf) == 0) {
757 h = Context->hdrs[Context->msgcount - 1];
758 mutt_sort_headers (Context, 0);
759 menu->current = h->virtual;
760 menu->redraw = REDRAW_FULL;
763 mutt_error (_("Article %s not found on server"), buf);
768 case OP_GET_CHILDREN:
769 case OP_RECONSTRUCT_THREAD:
771 if (Context->magic == M_NNTP) {
773 int old = CURHDR->index;
775 if (!CURHDR->env->message_id) {
776 mutt_error (_("No Message-ID. Unable to perform operation"));
781 if (!Context->id_hash)
782 Context->id_hash = mutt_make_id_hash (Context);
783 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
785 if (op == OP_RECONSTRUCT_THREAD) {
786 string_list_t *ref = CURHDR->env->references;
789 nntp_check_msgid (Context, ref->data);
790 /* the last msgid in References is the root message */
792 m_strcpy(buf, sizeof(buf), ref->data);
796 mutt_message (_("Check for children of message..."));
798 if (nntp_check_children (Context, buf) == 0) {
799 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
800 h = hash_find (Context->id_hash, buf);
801 /* if the root message was retrieved, move to it */
803 menu->current = h->virtual;
804 else /* try to restore old position */
805 for (i = 0; i < Context->msgcount; i++)
806 if (Context->hdrs[i]->index == old) {
807 menu->current = Context->hdrs[i]->virtual;
808 /* As an added courtesy, recenter the menu
809 * with the current entry at the middle of the screen */
810 menu_check_recenter (menu);
811 menu_current_middle (menu);
814 menu->redraw = REDRAW_FULL;
824 if (isdigit (LastKey))
825 mutt_ungetch (LastKey, 0);
827 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
831 if (!isdigit ((unsigned char) buf[0])) {
832 mutt_error (_("Argument must be a message number."));
838 if (i > 0 && i <= Context->msgcount) {
839 for (j = i - 1; j < Context->msgcount; j++) {
840 if (Context->hdrs[j]->virtual != -1)
843 if (j >= Context->msgcount) {
844 for (j = i - 2; j >= 0; j--) {
845 if (Context->hdrs[j]->virtual != -1)
851 menu->current = Context->hdrs[j]->virtual;
852 if (menu->menu == MENU_PAGER) {
853 op = OP_DISPLAY_MESSAGE;
857 menu->redraw = REDRAW_MOTION;
860 mutt_error (_("That message is not visible."));
863 mutt_error (_("Invalid message number."));
867 /* --------------------------------------------------------------------
868 * `index' specific commands
871 case OP_MAIN_DELETE_PATTERN:
877 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
880 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
881 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
884 case OP_MAIN_FETCH_MAIL:
888 menu->redraw = REDRAW_FULL;
893 mutt_help (MENU_MAIN);
894 menu->redraw = REDRAW_FULL;
897 case OP_MAIN_SHOW_LIMIT:
899 if (!Context->pattern)
900 mutt_message (_("No limit pattern is in effect."));
905 /* i18n: ask for a limit to apply */
906 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
907 mutt_message ("%s", buffer);
915 menu->oldcurrent = (Context->vcount && menu->current >= 0
917 Context->vcount) ? CURHDR->index : -1;
918 if (op == OP_TOGGLE_READ) {
919 char buffer[LONG_STRING];
921 if (m_strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
922 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
923 Context->pattern ? Context->pattern : ".*");
924 set_option (OPTHIDEREAD);
927 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
928 if (m_strncmp (buf, ".*", 2) == 0)
929 snprintf (buf, sizeof (buf), "~A");
930 unset_option (OPTHIDEREAD);
932 p_delete(&Context->pattern);
933 Context->pattern = m_strdup(buf);
935 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
936 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
938 if (menu->oldcurrent >= 0) {
939 /* try to find what used to be the current message */
941 for (i = 0; i < Context->vcount; i++)
942 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
946 if (menu->current < 0)
951 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
952 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
953 mutt_draw_tree (Context);
954 menu->redraw = REDRAW_FULL;
956 if (Context->pattern)
957 mutt_message _("To view all messages, limit to \"all\".");
968 if (query_quadoption2(mod_core.quit, _("Quit Madmutt?")) == M_YES) {
971 oldcount = Context ? Context->msgcount : 0;
974 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
977 if (check == M_NEW_MAIL || check == M_REOPENED)
978 update_index (menu, Context, check, oldcount, index_hint);
980 menu->redraw = REDRAW_FULL; /* new mail arrived? */
981 set_option (OPTSEARCHINVALID);
988 clearok (stdscr, TRUE);
989 menu->redraw = REDRAW_FULL;
993 case OP_SEARCH_REVERSE:
995 case OP_SEARCH_OPPOSITE:
999 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1000 menu->current = menu->oldcurrent;
1002 menu->redraw = REDRAW_MOTION;
1006 case OP_SORT_REVERSE:
1008 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1009 if (Context && Context->msgcount) {
1010 resort_index (menu);
1011 set_option (OPTSEARCHINVALID);
1020 if (tag && !option (OPTAUTOTAG)) {
1021 for (j = 0; j < Context->vcount; j++)
1022 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1023 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1026 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1027 Context->last_tag = CURHDR->tagged ? CURHDR :
1028 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1029 ? NULL : Context->last_tag);
1030 menu->redraw = REDRAW_STATUS;
1031 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1033 menu->redraw |= REDRAW_MOTION_RESYNCH;
1036 menu->redraw |= REDRAW_CURRENT;
1040 case OP_MAIN_TAG_PATTERN:
1044 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1045 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1048 case OP_MAIN_UNDELETE_PATTERN:
1054 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1056 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1058 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1061 case OP_MAIN_UNTAG_PATTERN:
1065 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1066 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1069 /* --------------------------------------------------------------------
1070 * The following operations can be performed inside of the pager.
1073 case OP_MAIN_IMAP_FETCH:
1074 if (Context->magic == M_IMAP)
1075 imap_check_mailbox (Context, &index_hint, 1);
1078 case OP_MAIN_SYNC_FOLDER:
1080 if (Context && !Context->msgcount)
1087 int oldvcount = Context->vcount;
1088 oldcount = Context->msgcount;
1092 /* calculate the number of messages _above_ the cursor,
1093 * so we can keep the cursor on the current message
1095 for (j = 0; j <= menu->current; j++) {
1096 if (Context->hdrs[Context->v2r[j]]->deleted)
1100 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1101 if (Context->vcount != oldvcount)
1102 menu->current -= dcount;
1103 set_option (OPTSEARCHINVALID);
1105 else if (check == M_NEW_MAIL || check == M_REOPENED)
1106 update_index (menu, Context, check, oldcount, index_hint);
1109 * do a sanity check even if mx_sync_mailbox failed.
1112 if (menu->current < 0 || menu->current >= Context->vcount)
1113 menu->current = ci_first_message ();
1116 /* check for a fatal error, or all messages deleted */
1120 /* if we were in the pager, redisplay the message */
1121 if (menu->menu == MENU_PAGER) {
1122 op = OP_DISPLAY_MESSAGE;
1126 menu->redraw = REDRAW_FULL;
1129 case OP_SIDEBAR_OPEN:
1130 case OP_MAIN_CHANGE_FOLDER:
1131 case OP_MAIN_CHANGE_FOLDER_READONLY:
1133 case OP_MAIN_CHANGE_GROUP:
1134 case OP_MAIN_CHANGE_GROUP_READONLY:
1136 if (attach_msg || option (OPTREADONLY) ||
1138 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1140 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1146 cp = _("Open mailbox in read-only mode");
1148 cp = _("Open mailbox");
1152 unset_option (OPTNEWS);
1153 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1154 set_option (OPTNEWS);
1155 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1158 cp = _("Open newsgroup in read-only mode");
1160 cp = _("Open newsgroup");
1161 nntp_buffy (buf, sizeof (buf));
1166 if (Context && Context->path)
1167 m_strcpy(buf, sizeof(buf), Context->path);
1168 if (op != OP_SIDEBAR_OPEN)
1169 buffy_next (buf, sizeof (buf));
1172 if (op == OP_SIDEBAR_OPEN) {
1173 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1175 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1176 if (menu->menu == MENU_PAGER) {
1177 op = OP_DISPLAY_MESSAGE;
1183 CLEARLINE (LINES - 1);
1188 if (option (OPTNEWS)) {
1189 unset_option (OPTNEWS);
1190 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1194 mutt_expand_path (buf, sizeof (buf));
1195 if (mx_get_magic (buf) <= 0) {
1196 mutt_error (_("%s is not a mailbox."), buf);
1199 m_strreplace(&CurrentFolder, buf);
1204 if (Context->cinfo && Context->realpath)
1205 m_strreplace(&LastFolder, Context->realpath);
1207 m_strreplace(&LastFolder, Context->path);
1208 oldcount = Context ? Context->msgcount : 0;
1210 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1211 if (check == M_NEW_MAIL || check == M_REOPENED)
1212 update_index (menu, Context, check, oldcount, index_hint);
1214 set_option (OPTSEARCHINVALID);
1215 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1223 /* Set CurrentMenu to MENU_MAIN before executing any folder
1224 * hooks so that all the index menu functions are available to
1228 CurrentMenu = MENU_MAIN;
1229 mutt_folder_hook (buf);
1231 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1232 menu->current = ci_first_message ();
1236 sidebar_set_current (buf);
1239 /* buffy_check() must be done with mail-reader mode! */
1240 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1242 && (Context->magic ==
1243 M_NNTP)) ? IndexNewsHelp :
1246 mutt_clear_error ();
1247 buffy_check (0); /* force the buffy check after we have changed
1249 menu->redraw = REDRAW_FULL;
1250 set_option (OPTSEARCHINVALID);
1253 case OP_DISPLAY_MESSAGE:
1254 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1259 * toggle the weeding of headers so that a user can press the key
1260 * again while reading the message.
1262 if (op == OP_DISPLAY_HEADERS)
1263 toggle_option (OPTWEED);
1265 unset_option (OPTNEEDRESORT);
1267 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1268 mutt_uncollapse_thread (Context, CURHDR);
1269 mutt_set_virtual (Context);
1270 if (option (OPTUNCOLLAPSEJUMP))
1271 menu->current = mutt_thread_next_unread (Context, CURHDR);
1274 if (option (OPTPGPAUTODEC) &&
1275 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1276 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1278 if ((op = mutt_display_message (CURHDR)) == -1) {
1279 unset_option (OPTNEEDRESORT);
1283 menu->menu = MENU_PAGER;
1284 menu->oldcurrent = menu->current;
1290 if (menu->menu == MENU_MAIN && attach_msg) {
1295 if ((menu->menu == MENU_MAIN)
1296 && (query_quadoption2(mod_core.quit,
1297 _("Exit Madmutt without saving?")) == M_YES))
1300 mx_fastclose_mailbox (Context);
1312 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1313 /* if we were in the pager, redisplay the message */
1314 if (menu->menu == MENU_PAGER) {
1315 op = OP_DISPLAY_MESSAGE;
1319 menu->redraw = REDRAW_CURRENT;
1322 case OP_MAIN_BREAK_THREAD:
1328 if ((Sort & SORT_MASK) != SORT_THREADS)
1329 mutt_error (_("Threading is not enabled."));
1333 HEADER *oldcur = CURHDR;
1335 mutt_break_thread (CURHDR);
1336 mutt_sort_headers (Context, 1);
1337 menu->current = oldcur->virtual;
1340 Context->changed = 1;
1341 mutt_message _("Thread broken");
1343 if (menu->menu == MENU_PAGER) {
1344 op = OP_DISPLAY_MESSAGE;
1348 menu->redraw |= REDRAW_INDEX;
1352 case OP_MAIN_LINK_THREADS:
1358 if ((Sort & SORT_MASK) != SORT_THREADS)
1359 mutt_error (_("Threading is not enabled."));
1361 else if (!CURHDR->env->message_id)
1362 mutt_error (_("No Message-ID: header available to link thread"));
1364 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1365 mutt_error (_("First, please tag a message to be linked here"));
1368 HEADER *oldcur = CURHDR;
1370 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1372 mutt_sort_headers (Context, 1);
1373 menu->current = oldcur->virtual;
1375 Context->changed = 1;
1376 mutt_message _("Threads linked");
1379 mutt_error (_("No thread linked"));
1382 if (menu->menu == MENU_PAGER) {
1383 op = OP_DISPLAY_MESSAGE;
1387 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1390 case OP_MAIN_NEXT_UNDELETED:
1394 if (menu->current >= Context->vcount - 1) {
1395 if (menu->menu == MENU_MAIN)
1396 mutt_error (_("You are on the last message."));
1400 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1401 menu->current = menu->oldcurrent;
1402 if (menu->menu == MENU_MAIN)
1403 mutt_error (_("No undeleted messages."));
1405 else if (menu->menu == MENU_PAGER) {
1406 op = OP_DISPLAY_MESSAGE;
1410 menu->redraw = REDRAW_MOTION;
1417 if (menu->current >= Context->vcount - 1) {
1418 if (menu->menu == MENU_MAIN)
1419 mutt_error (_("You are on the last message."));
1424 if (menu->menu == MENU_PAGER) {
1425 op = OP_DISPLAY_MESSAGE;
1429 menu->redraw = REDRAW_MOTION;
1432 case OP_MAIN_PREV_UNDELETED:
1436 if (menu->current < 1) {
1437 mutt_error (_("You are on the first message."));
1441 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1442 menu->current = menu->oldcurrent;
1443 if (menu->menu == MENU_MAIN)
1444 mutt_error (_("No undeleted messages."));
1446 else if (menu->menu == MENU_PAGER) {
1447 op = OP_DISPLAY_MESSAGE;
1451 menu->redraw = REDRAW_MOTION;
1458 if (menu->current < 1) {
1459 if (menu->menu == MENU_MAIN)
1460 mutt_error (_("You are on the first message."));
1465 if (menu->menu == MENU_PAGER) {
1466 op = OP_DISPLAY_MESSAGE;
1470 menu->redraw = REDRAW_MOTION;
1473 case OP_DECRYPT_COPY:
1474 case OP_DECRYPT_SAVE:
1475 case OP_COPY_MESSAGE:
1477 case OP_DECODE_COPY:
1478 case OP_DECODE_SAVE:
1481 if (mutt_save_message (tag ? NULL : CURHDR,
1482 (op == OP_DECRYPT_SAVE) ||
1483 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1484 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1485 (op == OP_DECRYPT_SAVE)
1486 || (op == OP_DECRYPT_COPY)
1487 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1494 menu->redraw |= REDRAW_INDEX;
1495 else if (option (OPTRESOLVE)) {
1496 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1497 menu->current = menu->oldcurrent;
1498 menu->redraw |= REDRAW_CURRENT;
1501 menu->redraw |= REDRAW_MOTION_RESYNCH;
1504 menu->redraw |= REDRAW_CURRENT;
1508 case OP_MAIN_NEXT_NEW:
1509 case OP_MAIN_NEXT_UNREAD:
1510 case OP_MAIN_PREV_NEW:
1511 case OP_MAIN_PREV_UNREAD:
1512 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1513 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1516 int first_unread = -1;
1524 for (j = 0; j != Context->vcount; j++) {
1525 #define CURHDRi Context->hdrs[Context->v2r[i]]
1526 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1527 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1529 if (i > Context->vcount - 1) {
1530 mutt_message _("Search wrapped to top.");
1538 mutt_message _("Search wrapped to bottom.");
1540 i = Context->vcount - 1;
1544 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1545 if (UNREAD (CURHDRi) && first_unread == -1)
1547 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1550 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1551 if (first_unread == -1)
1553 if ((!CURHDRi->old) && first_new == -1)
1557 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1560 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1561 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1562 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1567 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1568 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1569 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1571 menu->current = first_new;
1572 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1573 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1574 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1575 && first_unread != -1)
1576 menu->current = first_unread;
1578 if (menu->current == -1) {
1579 menu->current = menu->oldcurrent;
1580 mutt_error ("%s%s.",
1581 (op == OP_MAIN_NEXT_NEW
1583 OP_MAIN_PREV_NEW) ? _("No new messages") :
1584 _("No unread messages"),
1585 Context->pattern ? _(" in this limited view") : "");
1587 else if (menu->menu == MENU_PAGER) {
1588 op = OP_DISPLAY_MESSAGE;
1592 menu->redraw = REDRAW_MOTION;
1595 case OP_FLAG_MESSAGE:
1601 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1604 for (j = 0; j < Context->vcount; j++) {
1605 if (Context->hdrs[Context->v2r[j]]->tagged)
1606 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1607 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1610 menu->redraw |= REDRAW_INDEX;
1613 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1614 if (option (OPTRESOLVE)) {
1615 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1616 menu->current = menu->oldcurrent;
1617 menu->redraw = REDRAW_CURRENT;
1620 menu->redraw = REDRAW_MOTION_RESYNCH;
1623 menu->redraw = REDRAW_CURRENT;
1625 menu->redraw |= REDRAW_STATUS;
1634 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1637 for (j = 0; j < Context->vcount; j++) {
1638 if (Context->hdrs[Context->v2r[j]]->tagged) {
1639 if (Context->hdrs[Context->v2r[j]]->read ||
1640 Context->hdrs[Context->v2r[j]]->old)
1641 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1644 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1648 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1651 if (CURHDR->read || CURHDR->old)
1652 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1654 mutt_set_flag (Context, CURHDR, M_READ, 1);
1656 if (option (OPTRESOLVE)) {
1657 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1658 menu->current = menu->oldcurrent;
1659 menu->redraw = REDRAW_CURRENT;
1662 menu->redraw = REDRAW_MOTION_RESYNCH;
1665 menu->redraw = REDRAW_CURRENT;
1666 menu->redraw |= REDRAW_STATUS;
1670 case OP_TOGGLE_WRITE:
1673 if (mx_toggle_write (Context) == 0)
1674 menu->redraw |= REDRAW_STATUS;
1677 case OP_MAIN_NEXT_THREAD:
1678 case OP_MAIN_NEXT_SUBTHREAD:
1679 case OP_MAIN_PREV_THREAD:
1680 case OP_MAIN_PREV_SUBTHREAD:
1685 case OP_MAIN_NEXT_THREAD:
1686 menu->current = mutt_next_thread (CURHDR);
1689 case OP_MAIN_NEXT_SUBTHREAD:
1690 menu->current = mutt_next_subthread (CURHDR);
1693 case OP_MAIN_PREV_THREAD:
1694 menu->current = mutt_previous_thread (CURHDR);
1697 case OP_MAIN_PREV_SUBTHREAD:
1698 menu->current = mutt_previous_subthread (CURHDR);
1702 if (menu->current < 0) {
1703 menu->current = menu->oldcurrent;
1704 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1705 mutt_error (_("No more threads."));
1708 mutt_error (_("You are on the first thread."));
1710 else if (menu->menu == MENU_PAGER) {
1711 op = OP_DISPLAY_MESSAGE;
1715 menu->redraw = REDRAW_MOTION;
1718 case OP_MAIN_PARENT_MESSAGE:
1723 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1724 menu->current = menu->oldcurrent;
1726 else if (menu->menu == MENU_PAGER) {
1727 op = OP_DISPLAY_MESSAGE;
1731 menu->redraw = REDRAW_MOTION;
1734 case OP_MAIN_SET_FLAG:
1735 case OP_MAIN_CLEAR_FLAG:
1741 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0) {
1742 menu->redraw = REDRAW_STATUS;
1744 menu->redraw |= REDRAW_INDEX;
1745 else if (option (OPTRESOLVE)) {
1746 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1747 menu->current = menu->oldcurrent;
1748 menu->redraw |= REDRAW_CURRENT;
1751 menu->redraw |= REDRAW_MOTION_RESYNCH;
1754 menu->redraw |= REDRAW_CURRENT;
1758 case OP_MAIN_COLLAPSE_THREAD:
1762 if ((Sort & SORT_MASK) != SORT_THREADS) {
1763 mutt_error (_("Threading is not enabled."));
1768 if (CURHDR->collapsed) {
1769 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1770 mutt_set_virtual (Context);
1771 if (option (OPTUNCOLLAPSEJUMP))
1772 menu->current = mutt_thread_next_unread (Context, CURHDR);
1774 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1775 menu->current = mutt_collapse_thread (Context, CURHDR);
1776 mutt_set_virtual (Context);
1779 mutt_error (_("Thread contains unread messages."));
1784 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1788 case OP_MAIN_COLLAPSE_ALL:
1792 if ((Sort & SORT_MASK) != SORT_THREADS) {
1793 mutt_error (_("Threading is not enabled."));
1800 THREAD *thread, *top;
1803 if (CURHDR->collapsed)
1804 final = mutt_uncollapse_thread (Context, CURHDR);
1805 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1806 final = mutt_collapse_thread (Context, CURHDR);
1808 final = CURHDR->virtual;
1810 base = Context->hdrs[Context->v2r[final]];
1812 top = Context->tree;
1813 Context->collapsed = !Context->collapsed;
1814 while ((thread = top) != NULL) {
1815 while (!thread->message)
1816 thread = thread->child;
1817 h = thread->message;
1819 if (h->collapsed != Context->collapsed) {
1821 mutt_uncollapse_thread (Context, h);
1822 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1823 mutt_collapse_thread (Context, h);
1828 mutt_set_virtual (Context);
1829 for (j = 0; j < Context->vcount; j++) {
1830 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1836 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1840 /* --------------------------------------------------------------------
1841 * These functions are invoked directly from the internal-pager
1844 case OP_BOUNCE_MESSAGE:
1849 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1852 case OP_CREATE_ALIAS:
1854 mutt_create_alias (Context
1855 && Context->vcount ? CURHDR->env : NULL, NULL);
1856 MAYBE_REDRAW (menu->redraw);
1857 menu->redraw |= REDRAW_CURRENT;
1862 mutt_query_menu (NULL, 0);
1863 MAYBE_REDRAW (menu->redraw);
1866 case OP_PURGE_MESSAGE:
1873 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1876 mutt_tag_set_flag (M_DELETE, 1);
1877 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1878 if (option (OPTDELETEUNTAG))
1879 mutt_tag_set_flag (M_TAG, 0);
1880 menu->redraw = REDRAW_INDEX;
1883 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1884 mutt_set_flag (Context, CURHDR, M_PURGED,
1885 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1886 if (option (OPTDELETEUNTAG))
1887 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1888 if (option (OPTRESOLVE)) {
1889 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1890 menu->current = menu->oldcurrent;
1891 menu->redraw = REDRAW_CURRENT;
1893 else if (menu->menu == MENU_PAGER) {
1894 op = OP_DISPLAY_MESSAGE;
1898 menu->redraw |= REDRAW_MOTION_RESYNCH;
1901 menu->redraw = REDRAW_CURRENT;
1903 menu->redraw |= REDRAW_STATUS;
1906 case OP_DELETE_THREAD:
1907 case OP_DELETE_SUBTHREAD:
1913 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1915 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1916 op == OP_DELETE_THREAD ? 0 : 1);
1919 if (option (OPTDELETEUNTAG))
1920 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1921 op == OP_DELETE_THREAD ? 0 : 1);
1922 if (option (OPTRESOLVE))
1923 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1924 menu->current = menu->oldcurrent;
1925 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1931 if (Context && Context->magic == M_NNTP) {
1932 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1933 ((NNTP_DATA *) Context->data)->group))
1934 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1939 case OP_DISPLAY_ADDRESS:
1943 mutt_display_address (CURHDR->env);
1946 case OP_ENTER_COMMAND:
1948 CurrentMenu = MENU_MAIN;
1949 mutt_enter_command ();
1950 mutt_check_rescore (Context);
1951 if (option (OPTFORCEREDRAWINDEX))
1952 menu->redraw = REDRAW_FULL;
1953 unset_option (OPTFORCEREDRAWINDEX);
1954 unset_option (OPTFORCEREDRAWPAGER);
1957 case OP_EDIT_MESSAGE:
1964 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1966 if (option (OPTPGPAUTODEC)
1967 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1968 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1969 mutt_edit_message (Context, tag ? NULL : CURHDR);
1970 menu->redraw = REDRAW_FULL;
1974 case OP_FORWARD_MESSAGE:
1980 if (option (OPTPGPAUTODEC) &&
1981 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1982 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1983 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
1984 menu->redraw = REDRAW_FULL;
1987 case OP_GROUP_REPLY:
1993 if (option (OPTPGPAUTODEC) &&
1994 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1995 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1997 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
1998 tag ? NULL : CURHDR);
1999 menu->redraw = REDRAW_FULL;
2008 if (option (OPTPGPAUTODEC) &&
2009 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2010 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2012 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2013 tag ? NULL : CURHDR);
2014 menu->redraw = REDRAW_FULL;
2020 ci_send_message (0, NULL, NULL, Context, NULL);
2021 menu->redraw = REDRAW_FULL;
2024 case OP_EXTRACT_KEYS:
2027 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2028 menu->redraw = REDRAW_FULL;
2032 case OP_CHECK_TRADITIONAL:
2035 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2036 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2038 if (menu->menu == MENU_PAGER) {
2039 op = OP_DISPLAY_MESSAGE;
2047 mutt_pipe_message (tag ? NULL : CURHDR);
2048 MAYBE_REDRAW (menu->redraw);
2054 mutt_print_message (tag ? NULL : CURHDR);
2057 case OP_MAIN_READ_THREAD:
2058 case OP_MAIN_READ_SUBTHREAD:
2063 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2065 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2066 op == OP_MAIN_READ_THREAD ? 0 : 1);
2069 if (option (OPTRESOLVE)) {
2070 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2071 mutt_next_thread (CURHDR) :
2072 mutt_next_subthread (CURHDR))) == -1)
2073 menu->current = menu->oldcurrent;
2075 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2079 case OP_RECALL_MESSAGE:
2082 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2083 menu->redraw = REDRAW_FULL;
2093 for (j = 0; j < Context->vcount; j++) {
2094 if (Context->hdrs[Context->v2r[j]]->tagged)
2095 mutt_resend_message (NULL, Context,
2096 Context->hdrs[Context->v2r[j]]);
2100 mutt_resend_message (NULL, Context, CURHDR);
2102 menu->redraw = REDRAW_FULL;
2108 case OP_FORWARD_TO_GROUP:
2111 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2112 Context && Context->msgcount == 0) {
2113 mutt_error (_("There are no messages."));
2116 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2117 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2118 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2119 _("Reply by mail as poster prefers?")) !=
2121 if (Context && Context->magic == M_NNTP
2122 && !((NNTP_DATA *) Context->data)->allowed
2123 && query_quadoption (OPT_TOMODERATED,
2125 ("Posting to this group not allowed, may be moderated. Continue?"))
2129 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2132 if (op == OP_FOLLOWUP)
2133 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2134 tag ? NULL : CURHDR);
2136 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2137 tag ? NULL : CURHDR);
2139 menu->redraw = REDRAW_FULL;
2150 if (option (OPTPGPAUTODEC) &&
2151 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2152 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2154 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2155 menu->redraw = REDRAW_FULL;
2158 case OP_SHELL_ESCAPE:
2160 mutt_shell_escape ();
2161 MAYBE_REDRAW (menu->redraw);
2165 case OP_TAG_SUBTHREAD:
2169 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2170 op == OP_TAG_THREAD ? 0 : 1);
2173 if (option (OPTRESOLVE)) {
2174 menu->current = mutt_next_thread (CURHDR);
2176 if (menu->current == -1)
2177 menu->current = menu->oldcurrent;
2179 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2189 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2192 mutt_tag_set_flag (M_DELETE, 0);
2193 mutt_tag_set_flag (M_PURGED, 0);
2194 menu->redraw = REDRAW_INDEX;
2197 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2198 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2199 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2201 menu->redraw = REDRAW_MOTION_RESYNCH;
2204 menu->redraw = REDRAW_CURRENT;
2206 menu->redraw |= REDRAW_STATUS;
2209 case OP_UNDELETE_THREAD:
2210 case OP_UNDELETE_SUBTHREAD:
2216 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2218 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2219 op == OP_UNDELETE_THREAD ? 0 : 1)
2220 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2221 op == OP_UNDELETE_THREAD ? 0 : 1);
2224 if (option (OPTRESOLVE)) {
2225 if (op == OP_UNDELETE_THREAD)
2226 menu->current = mutt_next_thread (CURHDR);
2228 menu->current = mutt_next_subthread (CURHDR);
2230 if (menu->current == -1)
2231 menu->current = menu->oldcurrent;
2233 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2242 if (option (OPTFORCEBUFFYCHECK))
2245 menu->redraw = REDRAW_FULL;
2248 case OP_VIEW_ATTACHMENTS:
2251 mutt_view_attachments (CURHDR);
2252 if (CURHDR->attach_del)
2253 Context->changed = 1;
2254 menu->redraw = REDRAW_FULL;
2264 case OP_SIDEBAR_SCROLL_UP:
2265 case OP_SIDEBAR_SCROLL_DOWN:
2266 case OP_SIDEBAR_NEXT:
2267 case OP_SIDEBAR_PREV:
2268 case OP_SIDEBAR_NEXT_NEW:
2269 case OP_SIDEBAR_PREV_NEW:
2270 sidebar_scroll (op);
2273 if (menu->menu == MENU_MAIN)
2274 km_error_key (MENU_MAIN);
2277 if (menu->menu == MENU_PAGER) {
2278 menu->menu = MENU_MAIN;
2279 menu->redraw = REDRAW_FULL;
2287 /* Close all open IMAP connections */
2290 /* Close all open NNTP connections */
2295 mutt_menuDestroy (&menu);
2299 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2306 for (color = ColorIndexList; color; color = color->next)
2307 if (mutt_pattern_exec
2308 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2309 curhdr->pair = color->pair;
2312 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];