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>
17 #include <lib-crypt/crypt.h>
28 #include "recvattach.h"
32 #include <imap/imap_private.h>
35 #include <nntp/nntp.h>
39 #include "mutt_sasl.h"
42 static const char *No_mailbox_is_open = N_("No mailbox is open.");
43 static const char *There_are_no_messages = N_("There are no messages.");
44 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
45 static const char *Function_not_permitted_in_attach_message_mode =
46 N_("Function not permitted in attach-message mode.");
47 static const char *No_visible = N_("No visible messages.");
49 #define CHECK_IN_MAILBOX if (!Context) \
52 mutt_error (_(No_mailbox_is_open)); \
56 #define CHECK_MSGCOUNT if (!Context) \
59 mutt_error(_(No_mailbox_is_open)); \
62 else if (!Context->msgcount) \
65 mutt_error(_(There_are_no_messages)); \
69 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
72 mutt_error(_(No_visible)); \
77 #define CHECK_READONLY if (Context->readonly) \
80 mutt_error(_(Mailbox_is_read_only)); \
84 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
87 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
91 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
92 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
93 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
94 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
96 extern size_t UngetCount;
98 void index_make_entry (char *s, ssize_t l, struct menu_t * menu, int num)
100 format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_INDEX;
101 int edgemsgno, reverse = Sort & SORT_REVERSE;
102 HEADER *h = Context->hdrs[Context->v2r[num]];
105 if (option(OPTARROWCURSOR))
106 flag |= M_FORMAT_ARROWCURSOR;
108 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
109 flag |= M_FORMAT_TREE; /* display the thread tree */
110 if (h->display_subject)
111 flag |= M_FORMAT_FORCESUBJ;
114 if (menu->top + menu->pagelen > menu->max)
115 edgemsgno = Context->v2r[menu->max - 1];
117 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
120 edgemsgno = Context->v2r[menu->top];
122 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
126 /* if no ancestor is visible on current screen, provisionally force
128 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
130 flag |= M_FORMAT_FORCESUBJ;
133 else if (tmp->message->virtual >= 0)
136 if (flag & M_FORMAT_FORCESUBJ) {
137 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
141 /* ...but if a previous sibling is available, don't force it */
142 if (reverse ? tmp->message->msgno >
143 edgemsgno : tmp->message->msgno < edgemsgno)
145 else if (tmp->message->virtual >= 0) {
146 flag &= ~M_FORMAT_FORCESUBJ;
154 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
157 int index_color (int index_no)
159 HEADER *h = Context->hdrs[Context->v2r[index_no]];
164 mutt_set_header_color (Context, h);
168 static int ci_next_undeleted (int msgno)
172 for (i = msgno + 1; i < Context->vcount; i++)
173 if (!Context->hdrs[Context->v2r[i]]->deleted)
178 static int ci_previous_undeleted (int msgno)
182 for (i = msgno - 1; i >= 0; i--)
183 if (!Context->hdrs[Context->v2r[i]]->deleted)
188 /* Return the index of the first new message, or failing that, the first
191 static int ci_first_message (void)
195 if (Context && Context->msgcount) {
196 for (i = 0; i < Context->vcount; i++) {
197 if (!Context->hdrs[Context->v2r[i]]->read &&
198 !Context->hdrs[Context->v2r[i]]->deleted) {
199 if (!Context->hdrs[Context->v2r[i]]->old)
208 /* If Sort is reverse and not threaded, the latest message is first.
209 * If Sort is threaded, the latest message is first iff exactly one
210 * of Sort and SortAux are reverse.
212 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
213 ((Sort & SORT_MASK) == SORT_THREADS &&
214 ((Sort ^ SortAux) & SORT_REVERSE)))
217 return (Context->vcount ? Context->vcount - 1 : 0);
222 /* This should be in mx.c, but it only gets used here. */
223 static int mx_toggle_write (CONTEXT * ctx)
229 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
234 if (ctx->dontwrite) {
236 mutt_message (_("Changes to folder will be written on folder exit."));
240 mutt_message (_("Changes to folder will not be written."));
246 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
247 int oldcount, int index_hint)
249 /* store pointers to the newly added messages */
250 HEADER **save_new = NULL;
253 /* take note of the current message */
255 if (menu->current < Context->vcount)
256 menu->oldcurrent = index_hint;
258 oldcount = 0; /* invalid message number! */
261 /* We are in a limited view. Check if the new message(s) satisfy
262 * the limit criteria. If they do, set their virtual msgno so that
263 * they will be visible in the limited view */
264 if (Context->pattern) {
265 #define THIS_BODY Context->hdrs[j]->content
266 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
267 if (mutt_pattern_exec
268 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
270 Context->hdrs[j]->virtual = Context->vcount;
271 Context->v2r[Context->vcount] = j;
272 Context->hdrs[j]->limited = 1;
275 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
281 /* save the list of new messages */
282 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
283 save_new = p_new(HEADER*, Context->msgcount - oldcount);
284 for (j = oldcount; j < Context->msgcount; j++)
285 save_new[j - oldcount] = Context->hdrs[j];
288 /* if the mailbox was reopened, need to rethread from scratch */
289 mutt_sort_headers (Context, (check == M_REOPENED));
291 /* uncollapse threads with new mail */
292 if ((Sort & SORT_MASK) == SORT_THREADS) {
293 if (check == M_REOPENED) {
296 Context->collapsed = 0;
298 for (h = Context->tree; h; h = h->next) {
299 for (c = h; !c->message; c = c->child);
300 mutt_uncollapse_thread (Context, c->message);
302 mutt_set_virtual (Context);
305 for (j = 0; j < Context->msgcount - oldcount; j++) {
308 for (k = 0; k < Context->msgcount; k++) {
309 HEADER *h = Context->hdrs[k];
311 if (h == save_new[j] && (!Context->pattern || h->limited))
312 mutt_uncollapse_thread (Context, h);
316 mutt_set_virtual (Context);
322 /* restore the current message to the message it was pointing to */
323 for (j = 0; j < Context->vcount; j++) {
324 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
331 if (menu->current < 0)
332 menu->current = ci_first_message ();
335 static void resort_index (MUTTMENU * menu)
338 HEADER *current = CURHDR;
341 mutt_sort_headers (Context, 0);
342 /* Restore the current message */
344 for (i = 0; i < Context->vcount; i++) {
345 if (Context->hdrs[Context->v2r[i]] == current) {
351 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
352 menu->current = mutt_parent_message (Context, current);
354 if (menu->current < 0)
355 menu->current = ci_first_message ();
357 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
360 struct mapping_t IndexHelp[] = {
361 {N_("Quit"), OP_QUIT},
362 {N_("Del"), OP_DELETE},
363 {N_("Undel"), OP_UNDELETE},
364 {N_("Save"), OP_SAVE},
365 {N_("Mail"), OP_MAIL},
366 {N_("Reply"), OP_REPLY},
367 {N_("Group"), OP_GROUP_REPLY},
368 {N_("Help"), OP_HELP},
373 struct mapping_t IndexNewsHelp[] = {
374 {N_("Quit"), OP_QUIT},
375 {N_("Del"), OP_DELETE},
376 {N_("Undel"), OP_UNDELETE},
377 {N_("Save"), OP_SAVE},
378 {N_("Post"), OP_POST},
379 {N_("Followup"), OP_FOLLOWUP},
380 {N_("Catchup"), OP_CATCHUP},
381 {N_("Help"), OP_HELP},
386 /* This function handles the message index window as well as commands returned
387 * from the pager (MENU_PAGER).
389 int mutt_index_menu (void)
391 char buf[LONG_STRING], helpstr[STRING];
394 int done = 0; /* controls when to exit the "event" loop */
396 int tag = 0; /* has the tag-prefix command been pressed? */
401 char *cp; /* temporary variable. */
402 int index_hint; /* used to restore cursor position */
403 int do_buffy_notify = 1;
404 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
405 int attach_msg = option (OPTATTACHMSG);
407 menu = mutt_new_menu ();
408 menu->menu = MENU_MAIN;
410 menu->pagelen = LINES - 3;
411 menu->make_entry = (void *) index_make_entry;
412 menu->color = index_color;
413 menu->current = ci_first_message ();
414 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
417 && (Context->magic ==
418 M_NNTP)) ? IndexNewsHelp :
423 buffy_check (0); /* force the buffy check after we enter the folder */
424 /* record folder we open to place sidebar indicator properly */
425 if (Context && Context->path)
426 sidebar_set_current (Context->path);
430 tag = 0; /* clear the tag-prefix */
432 menu->max = Context ? Context->vcount : 0;
433 oldcount = Context ? Context->msgcount : 0;
435 /* check if we need to resort the index because just about
436 * any 'op' below could do mutt_enter_command(), either here or
437 * from any new menu launched, and change $sort/$sort_aux
439 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
442 if (option (OPTREDRAWTREE) && Context && Context->msgcount
443 && (Sort & SORT_MASK) == SORT_THREADS) {
444 mutt_draw_tree (Context);
445 menu->redraw |= REDRAW_STATUS;
446 unset_option (OPTREDRAWTREE);
449 if (Context && !attach_msg) {
452 /* check for new mail in the mailbox. If nonzero, then something has
453 * changed about the file (either we got new mail or the file was
454 * modified underneath us.)
457 imap_allow_reopen (Context);
459 index_hint = (Context->vcount && menu->current >= 0
460 && menu->current < Context->vcount) ? CURHDR->index : 0;
462 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
463 if (!Context->path) {
464 /* fatal error occurred */
466 menu->redraw = REDRAW_FULL;
468 set_option (OPTSEARCHINVALID);
470 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
471 update_index (menu, Context, check, oldcount, index_hint);
473 /* notify the user of new mail */
474 if (check == M_REOPENED)
476 ("Mailbox was externally modified. Flags may be wrong."));
477 else if (check == M_NEW_MAIL) {
478 /* on new mail: redraw sidebar */
480 mutt_message (_("New mail in this mailbox."));
482 if (option (OPTBEEPNEW))
485 else if (check == M_FLAGS)
486 mutt_message (_("Mailbox was externally modified."));
488 /* avoid the message being overwritten by buffy */
491 menu->redraw = REDRAW_FULL;
492 menu->max = Context->vcount;
494 set_option (OPTSEARCHINVALID);
499 imap_disallow_reopen (Context);
502 /* check for new mail in the incoming folders */
504 if ((newcount = buffy_check (0)) != oldcount) {
505 menu->redraw |= REDRAW_STATUS;
506 menu->redraw |= REDRAW_SIDEBAR;
508 if (do_buffy_notify) {
509 if (buffy_notify () && option (OPTBEEPNEW))
518 if (menu->redraw & REDRAW_SIDEBAR)
520 if (menu->redraw & REDRAW_FULL) {
521 menu_redraw_full (menu);
526 if (menu->menu == MENU_MAIN) {
527 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
528 menu_check_recenter (menu);
530 if (menu->redraw & REDRAW_INDEX) {
531 menu_redraw_index (menu);
532 menu->redraw |= REDRAW_STATUS;
534 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
535 menu_redraw_motion (menu);
536 else if (menu->redraw & REDRAW_CURRENT)
537 menu_redraw_current (menu);
540 if (menu->redraw & REDRAW_STATUS) {
541 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
542 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
543 sidebar_draw_frames();
544 SETCOLOR (MT_COLOR_STATUS);
545 BKGDSET (MT_COLOR_STATUS);
546 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
547 mutt_paddstr (COLS-SW, buf);
548 SETCOLOR (MT_COLOR_NORMAL);
549 BKGDSET (MT_COLOR_NORMAL);
550 sidebar_set_buffystats (Context);
551 menu->redraw &= ~REDRAW_STATUS;
552 if (option (OPTXTERMSETTITLES)) {
553 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermTitle));
554 printf("\033]2;%s\007", buf);
555 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermIcon));
556 printf("\033]1;%s\007", buf);
562 if (menu->current < menu->max)
563 menu->oldcurrent = menu->current;
565 menu->oldcurrent = -1;
567 if (option (OPTARROWCURSOR))
568 move (menu->current - menu->top + menu->offset, 2);
569 else if (option (OPTBRAILLEFRIENDLY))
570 move (menu->current - menu->top + menu->offset, 0);
572 move (menu->current - menu->top + menu->offset, COLS - 1);
575 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
578 mutt_resize_screen ();
579 menu->redraw = REDRAW_FULL;
580 menu->menu = MENU_MAIN;
582 menu->top = 0; /* so we scroll the right amount */
584 * force a real complete redraw. clrtobot() doesn't seem to be able
585 * to handle every case without this.
587 clearok (stdscr, TRUE);
592 op = km_dokey (MENU_MAIN);
595 continue; /* either user abort or timeout */
599 /* special handling for the tag-prefix function */
600 if (op == OP_TAG_PREFIX) {
602 mutt_error (_("No mailbox is open."));
607 if (!Context->tagged) {
608 mutt_error (_("No tagged messages."));
614 /* give visual indication that the next command is a tag- command */
615 mvaddstr (LINES - 1, 0, "tag-");
618 /* get the real command */
619 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
620 /* abort tag sequence */
621 CLEARLINE (LINES - 1);
625 else if (option (OPTAUTOTAG) && Context && Context->tagged)
628 if (op == OP_TAG_PREFIX_COND) {
630 mutt_error (_("No mailbox is open."));
635 if (!Context->tagged) {
638 while (UngetCount > 0) {
640 if (tmp.op == OP_END_COND)
643 mutt_message (_("Nothing to do."));
649 /* give visual indication that the next command is a tag- command */
650 mvaddstr (LINES - 1, 0, "tag-");
653 /* get the real command */
654 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
655 /* abort tag sequence */
656 CLEARLINE (LINES - 1);
664 if (menu->current < menu->max)
665 menu->oldcurrent = menu->current;
667 menu->oldcurrent = -1;
669 mutt_curs_set (1); /* fallback from the pager */
673 unset_option (OPTNEWS); /* for any case */
678 /* ----------------------------------------------------------------------
683 menu_bottom_page (menu);
686 menu_first_entry (menu);
689 menu_middle_page (menu);
695 menu_half_down (menu);
698 menu_next_line (menu);
701 menu_prev_line (menu);
704 menu_next_page (menu);
707 menu_prev_page (menu);
710 menu_last_entry (menu);
713 menu_top_page (menu);
716 menu_current_top (menu);
718 case OP_CURRENT_MIDDLE:
719 menu_current_middle (menu);
721 case OP_CURRENT_BOTTOM:
722 menu_current_bottom (menu);
729 if (Context->magic == M_NNTP) {
732 if (op == OP_GET_MESSAGE) {
734 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
739 string_list_t *ref = CURHDR->env->references;
742 mutt_error (_("Article has no parent reference!"));
746 m_strcpy(buf, sizeof(buf), ref->data);
748 if (!Context->id_hash)
749 Context->id_hash = mutt_make_id_hash (Context);
750 if ((h = hash_find (Context->id_hash, buf))) {
751 if (h->virtual != -1) {
752 menu->current = h->virtual;
753 menu->redraw = REDRAW_MOTION_RESYNCH;
755 else if (h->collapsed) {
756 mutt_uncollapse_thread (Context, h);
757 mutt_set_virtual (Context);
758 menu->current = h->virtual;
759 menu->redraw = REDRAW_MOTION_RESYNCH;
762 mutt_error (_("Message not visible in limited view."));
765 if (nntp_check_msgid (Context, buf) == 0) {
766 h = Context->hdrs[Context->msgcount - 1];
767 mutt_sort_headers (Context, 0);
768 menu->current = h->virtual;
769 menu->redraw = REDRAW_FULL;
772 mutt_error (_("Article %s not found on server"), buf);
777 case OP_GET_CHILDREN:
778 case OP_RECONSTRUCT_THREAD:
780 if (Context->magic == M_NNTP) {
782 int old = CURHDR->index;
784 if (!CURHDR->env->message_id) {
785 mutt_error (_("No Message-ID. Unable to perform operation"));
790 if (!Context->id_hash)
791 Context->id_hash = mutt_make_id_hash (Context);
792 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
794 if (op == OP_RECONSTRUCT_THREAD) {
795 string_list_t *ref = CURHDR->env->references;
798 nntp_check_msgid (Context, ref->data);
799 /* the last msgid in References is the root message */
801 m_strcpy(buf, sizeof(buf), ref->data);
805 mutt_message (_("Check for children of message..."));
807 if (nntp_check_children (Context, buf) == 0) {
808 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
809 h = hash_find (Context->id_hash, buf);
810 /* if the root message was retrieved, move to it */
812 menu->current = h->virtual;
813 else /* try to restore old position */
814 for (i = 0; i < Context->msgcount; i++)
815 if (Context->hdrs[i]->index == old) {
816 menu->current = Context->hdrs[i]->virtual;
817 /* As an added courtesy, recenter the menu
818 * with the current entry at the middle of the screen */
819 menu_check_recenter (menu);
820 menu_current_middle (menu);
823 menu->redraw = REDRAW_FULL;
833 if (isdigit (LastKey))
834 mutt_ungetch (LastKey, 0);
836 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
840 if (!isdigit ((unsigned char) buf[0])) {
841 mutt_error (_("Argument must be a message number."));
847 if (i > 0 && i <= Context->msgcount) {
848 for (j = i - 1; j < Context->msgcount; j++) {
849 if (Context->hdrs[j]->virtual != -1)
852 if (j >= Context->msgcount) {
853 for (j = i - 2; j >= 0; j--) {
854 if (Context->hdrs[j]->virtual != -1)
860 menu->current = Context->hdrs[j]->virtual;
861 if (menu->menu == MENU_PAGER) {
862 op = OP_DISPLAY_MESSAGE;
866 menu->redraw = REDRAW_MOTION;
869 mutt_error (_("That message is not visible."));
872 mutt_error (_("Invalid message number."));
876 /* --------------------------------------------------------------------
877 * `index' specific commands
880 case OP_MAIN_DELETE_PATTERN:
886 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
889 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
890 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
893 case OP_MAIN_FETCH_MAIL:
897 menu->redraw = REDRAW_FULL;
902 mutt_help (MENU_MAIN);
903 menu->redraw = REDRAW_FULL;
906 case OP_MAIN_SHOW_LIMIT:
908 if (!Context->pattern)
909 mutt_message (_("No limit pattern is in effect."));
914 /* i18n: ask for a limit to apply */
915 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
916 mutt_message ("%s", buffer);
924 menu->oldcurrent = (Context->vcount && menu->current >= 0
926 Context->vcount) ? CURHDR->index : -1;
927 if (op == OP_TOGGLE_READ) {
928 char buffer[LONG_STRING];
930 if (m_strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
931 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
932 Context->pattern ? Context->pattern : ".*");
933 set_option (OPTHIDEREAD);
936 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
937 if (m_strncmp (buf, ".*", 2) == 0)
938 snprintf (buf, sizeof (buf), "~A");
939 unset_option (OPTHIDEREAD);
941 p_delete(&Context->pattern);
942 Context->pattern = m_strdup(buf);
944 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
945 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
947 if (menu->oldcurrent >= 0) {
948 /* try to find what used to be the current message */
950 for (i = 0; i < Context->vcount; i++)
951 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
955 if (menu->current < 0)
960 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
961 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
962 mutt_draw_tree (Context);
963 menu->redraw = REDRAW_FULL;
965 if (Context->pattern)
966 mutt_message _("To view all messages, limit to \"all\".");
977 if (query_quadoption (OPT_QUIT, _("Quit Madmutt?")) == M_YES) {
980 oldcount = Context ? Context->msgcount : 0;
983 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
986 if (check == M_NEW_MAIL || check == M_REOPENED)
987 update_index (menu, Context, check, oldcount, index_hint);
989 menu->redraw = REDRAW_FULL; /* new mail arrived? */
990 set_option (OPTSEARCHINVALID);
997 clearok (stdscr, TRUE);
998 menu->redraw = REDRAW_FULL;
1002 case OP_SEARCH_REVERSE:
1003 case OP_SEARCH_NEXT:
1004 case OP_SEARCH_OPPOSITE:
1008 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1009 menu->current = menu->oldcurrent;
1011 menu->redraw = REDRAW_MOTION;
1015 case OP_SORT_REVERSE:
1017 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1018 if (Context && Context->msgcount) {
1019 resort_index (menu);
1020 set_option (OPTSEARCHINVALID);
1029 if (tag && !option (OPTAUTOTAG)) {
1030 for (j = 0; j < Context->vcount; j++)
1031 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1032 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1035 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1036 Context->last_tag = CURHDR->tagged ? CURHDR :
1037 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1038 ? NULL : Context->last_tag);
1039 menu->redraw = REDRAW_STATUS;
1040 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1042 menu->redraw |= REDRAW_MOTION_RESYNCH;
1045 menu->redraw |= REDRAW_CURRENT;
1049 case OP_MAIN_TAG_PATTERN:
1053 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1054 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1057 case OP_MAIN_UNDELETE_PATTERN:
1063 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1065 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1067 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1070 case OP_MAIN_UNTAG_PATTERN:
1074 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1075 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1078 /* --------------------------------------------------------------------
1079 * The following operations can be performed inside of the pager.
1082 case OP_MAIN_IMAP_FETCH:
1083 if (Context->magic == M_IMAP)
1084 imap_check_mailbox (Context, &index_hint, 1);
1087 case OP_MAIN_SYNC_FOLDER:
1089 if (Context && !Context->msgcount)
1096 int oldvcount = Context->vcount;
1097 oldcount = Context->msgcount;
1101 /* calculate the number of messages _above_ the cursor,
1102 * so we can keep the cursor on the current message
1104 for (j = 0; j <= menu->current; j++) {
1105 if (Context->hdrs[Context->v2r[j]]->deleted)
1109 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1110 if (Context->vcount != oldvcount)
1111 menu->current -= dcount;
1112 set_option (OPTSEARCHINVALID);
1114 else if (check == M_NEW_MAIL || check == M_REOPENED)
1115 update_index (menu, Context, check, oldcount, index_hint);
1118 * do a sanity check even if mx_sync_mailbox failed.
1121 if (menu->current < 0 || menu->current >= Context->vcount)
1122 menu->current = ci_first_message ();
1125 /* check for a fatal error, or all messages deleted */
1129 /* if we were in the pager, redisplay the message */
1130 if (menu->menu == MENU_PAGER) {
1131 op = OP_DISPLAY_MESSAGE;
1135 menu->redraw = REDRAW_FULL;
1138 case OP_SIDEBAR_OPEN:
1139 case OP_MAIN_CHANGE_FOLDER:
1140 case OP_MAIN_CHANGE_FOLDER_READONLY:
1142 case OP_MAIN_CHANGE_GROUP:
1143 case OP_MAIN_CHANGE_GROUP_READONLY:
1145 if (attach_msg || option (OPTREADONLY) ||
1147 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1149 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1155 cp = _("Open mailbox in read-only mode");
1157 cp = _("Open mailbox");
1161 unset_option (OPTNEWS);
1162 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1163 set_option (OPTNEWS);
1164 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1167 cp = _("Open newsgroup in read-only mode");
1169 cp = _("Open newsgroup");
1170 nntp_buffy (buf, sizeof (buf));
1175 if (Context && Context->path)
1176 m_strcpy(buf, sizeof(buf), Context->path);
1177 if (op != OP_SIDEBAR_OPEN)
1178 buffy_next (buf, sizeof (buf));
1181 if (op == OP_SIDEBAR_OPEN) {
1182 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1184 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1185 if (menu->menu == MENU_PAGER) {
1186 op = OP_DISPLAY_MESSAGE;
1192 CLEARLINE (LINES - 1);
1197 if (option (OPTNEWS)) {
1198 unset_option (OPTNEWS);
1199 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1203 mutt_expand_path (buf, sizeof (buf));
1204 if (mx_get_magic (buf) <= 0) {
1205 mutt_error (_("%s is not a mailbox."), buf);
1208 m_strreplace(&CurrentFolder, buf);
1213 if (Context->cinfo && Context->realpath)
1214 m_strreplace(&LastFolder, Context->realpath);
1216 m_strreplace(&LastFolder, Context->path);
1217 oldcount = Context ? Context->msgcount : 0;
1219 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1220 if (check == M_NEW_MAIL || check == M_REOPENED)
1221 update_index (menu, Context, check, oldcount, index_hint);
1223 set_option (OPTSEARCHINVALID);
1224 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1232 /* Set CurrentMenu to MENU_MAIN before executing any folder
1233 * hooks so that all the index menu functions are available to
1237 CurrentMenu = MENU_MAIN;
1238 mutt_folder_hook (buf);
1240 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1241 menu->current = ci_first_message ();
1245 sidebar_set_current (buf);
1248 /* buffy_check() must be done with mail-reader mode! */
1249 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1251 && (Context->magic ==
1252 M_NNTP)) ? IndexNewsHelp :
1255 mutt_clear_error ();
1256 buffy_check (0); /* force the buffy check after we have changed
1258 menu->redraw = REDRAW_FULL;
1259 set_option (OPTSEARCHINVALID);
1262 case OP_DISPLAY_MESSAGE:
1263 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1268 * toggle the weeding of headers so that a user can press the key
1269 * again while reading the message.
1271 if (op == OP_DISPLAY_HEADERS)
1272 toggle_option (OPTWEED);
1274 unset_option (OPTNEEDRESORT);
1276 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1277 mutt_uncollapse_thread (Context, CURHDR);
1278 mutt_set_virtual (Context);
1279 if (option (OPTUNCOLLAPSEJUMP))
1280 menu->current = mutt_thread_next_unread (Context, CURHDR);
1283 if (option (OPTPGPAUTODEC) &&
1284 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1285 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1287 if ((op = mutt_display_message (CURHDR)) == -1) {
1288 unset_option (OPTNEEDRESORT);
1292 menu->menu = MENU_PAGER;
1293 menu->oldcurrent = menu->current;
1299 if (menu->menu == MENU_MAIN && attach_msg) {
1304 if ((menu->menu == MENU_MAIN)
1305 && (query_quadoption (OPT_QUIT,
1306 _("Exit Madmutt without saving?")) == M_YES))
1309 mx_fastclose_mailbox (Context);
1321 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1322 /* if we were in the pager, redisplay the message */
1323 if (menu->menu == MENU_PAGER) {
1324 op = OP_DISPLAY_MESSAGE;
1328 menu->redraw = REDRAW_CURRENT;
1331 case OP_MAIN_BREAK_THREAD:
1337 if ((Sort & SORT_MASK) != SORT_THREADS)
1338 mutt_error (_("Threading is not enabled."));
1342 HEADER *oldcur = CURHDR;
1344 mutt_break_thread (CURHDR);
1345 mutt_sort_headers (Context, 1);
1346 menu->current = oldcur->virtual;
1349 Context->changed = 1;
1350 mutt_message _("Thread broken");
1352 if (menu->menu == MENU_PAGER) {
1353 op = OP_DISPLAY_MESSAGE;
1357 menu->redraw |= REDRAW_INDEX;
1361 case OP_MAIN_LINK_THREADS:
1367 if ((Sort & SORT_MASK) != SORT_THREADS)
1368 mutt_error (_("Threading is not enabled."));
1370 else if (!CURHDR->env->message_id)
1371 mutt_error (_("No Message-ID: header available to link thread"));
1373 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1374 mutt_error (_("First, please tag a message to be linked here"));
1377 HEADER *oldcur = CURHDR;
1379 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1381 mutt_sort_headers (Context, 1);
1382 menu->current = oldcur->virtual;
1384 Context->changed = 1;
1385 mutt_message _("Threads linked");
1388 mutt_error (_("No thread linked"));
1391 if (menu->menu == MENU_PAGER) {
1392 op = OP_DISPLAY_MESSAGE;
1396 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1399 case OP_MAIN_NEXT_UNDELETED:
1403 if (menu->current >= Context->vcount - 1) {
1404 if (menu->menu == MENU_MAIN)
1405 mutt_error (_("You are on the last message."));
1409 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1410 menu->current = menu->oldcurrent;
1411 if (menu->menu == MENU_MAIN)
1412 mutt_error (_("No undeleted messages."));
1414 else if (menu->menu == MENU_PAGER) {
1415 op = OP_DISPLAY_MESSAGE;
1419 menu->redraw = REDRAW_MOTION;
1426 if (menu->current >= Context->vcount - 1) {
1427 if (menu->menu == MENU_MAIN)
1428 mutt_error (_("You are on the last message."));
1433 if (menu->menu == MENU_PAGER) {
1434 op = OP_DISPLAY_MESSAGE;
1438 menu->redraw = REDRAW_MOTION;
1441 case OP_MAIN_PREV_UNDELETED:
1445 if (menu->current < 1) {
1446 mutt_error (_("You are on the first message."));
1450 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1451 menu->current = menu->oldcurrent;
1452 if (menu->menu == MENU_MAIN)
1453 mutt_error (_("No undeleted messages."));
1455 else if (menu->menu == MENU_PAGER) {
1456 op = OP_DISPLAY_MESSAGE;
1460 menu->redraw = REDRAW_MOTION;
1467 if (menu->current < 1) {
1468 if (menu->menu == MENU_MAIN)
1469 mutt_error (_("You are on the first message."));
1474 if (menu->menu == MENU_PAGER) {
1475 op = OP_DISPLAY_MESSAGE;
1479 menu->redraw = REDRAW_MOTION;
1482 case OP_DECRYPT_COPY:
1483 case OP_DECRYPT_SAVE:
1484 case OP_COPY_MESSAGE:
1486 case OP_DECODE_COPY:
1487 case OP_DECODE_SAVE:
1490 if (mutt_save_message (tag ? NULL : CURHDR,
1491 (op == OP_DECRYPT_SAVE) ||
1492 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1493 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1494 (op == OP_DECRYPT_SAVE)
1495 || (op == OP_DECRYPT_COPY)
1496 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1503 menu->redraw |= REDRAW_INDEX;
1504 else if (option (OPTRESOLVE)) {
1505 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1506 menu->current = menu->oldcurrent;
1507 menu->redraw |= REDRAW_CURRENT;
1510 menu->redraw |= REDRAW_MOTION_RESYNCH;
1513 menu->redraw |= REDRAW_CURRENT;
1517 case OP_MAIN_NEXT_NEW:
1518 case OP_MAIN_NEXT_UNREAD:
1519 case OP_MAIN_PREV_NEW:
1520 case OP_MAIN_PREV_UNREAD:
1521 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1522 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1525 int first_unread = -1;
1533 for (j = 0; j != Context->vcount; j++) {
1534 #define CURHDRi Context->hdrs[Context->v2r[i]]
1535 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1536 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1538 if (i > Context->vcount - 1) {
1539 mutt_message _("Search wrapped to top.");
1547 mutt_message _("Search wrapped to bottom.");
1549 i = Context->vcount - 1;
1553 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1554 if (UNREAD (CURHDRi) && first_unread == -1)
1556 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1559 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1560 if (first_unread == -1)
1562 if ((!CURHDRi->old) && first_new == -1)
1566 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1569 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1570 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1571 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1576 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1577 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1578 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1580 menu->current = first_new;
1581 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1582 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1583 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1584 && first_unread != -1)
1585 menu->current = first_unread;
1587 if (menu->current == -1) {
1588 menu->current = menu->oldcurrent;
1589 mutt_error ("%s%s.",
1590 (op == OP_MAIN_NEXT_NEW
1592 OP_MAIN_PREV_NEW) ? _("No new messages") :
1593 _("No unread messages"),
1594 Context->pattern ? _(" in this limited view") : "");
1596 else if (menu->menu == MENU_PAGER) {
1597 op = OP_DISPLAY_MESSAGE;
1601 menu->redraw = REDRAW_MOTION;
1604 case OP_FLAG_MESSAGE:
1610 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1613 for (j = 0; j < Context->vcount; j++) {
1614 if (Context->hdrs[Context->v2r[j]]->tagged)
1615 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1616 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1619 menu->redraw |= REDRAW_INDEX;
1622 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1623 if (option (OPTRESOLVE)) {
1624 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1625 menu->current = menu->oldcurrent;
1626 menu->redraw = REDRAW_CURRENT;
1629 menu->redraw = REDRAW_MOTION_RESYNCH;
1632 menu->redraw = REDRAW_CURRENT;
1634 menu->redraw |= REDRAW_STATUS;
1643 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1646 for (j = 0; j < Context->vcount; j++) {
1647 if (Context->hdrs[Context->v2r[j]]->tagged) {
1648 if (Context->hdrs[Context->v2r[j]]->read ||
1649 Context->hdrs[Context->v2r[j]]->old)
1650 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1653 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1657 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1660 if (CURHDR->read || CURHDR->old)
1661 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1663 mutt_set_flag (Context, CURHDR, M_READ, 1);
1665 if (option (OPTRESOLVE)) {
1666 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1667 menu->current = menu->oldcurrent;
1668 menu->redraw = REDRAW_CURRENT;
1671 menu->redraw = REDRAW_MOTION_RESYNCH;
1674 menu->redraw = REDRAW_CURRENT;
1675 menu->redraw |= REDRAW_STATUS;
1679 case OP_TOGGLE_WRITE:
1682 if (mx_toggle_write (Context) == 0)
1683 menu->redraw |= REDRAW_STATUS;
1686 case OP_MAIN_NEXT_THREAD:
1687 case OP_MAIN_NEXT_SUBTHREAD:
1688 case OP_MAIN_PREV_THREAD:
1689 case OP_MAIN_PREV_SUBTHREAD:
1694 case OP_MAIN_NEXT_THREAD:
1695 menu->current = mutt_next_thread (CURHDR);
1698 case OP_MAIN_NEXT_SUBTHREAD:
1699 menu->current = mutt_next_subthread (CURHDR);
1702 case OP_MAIN_PREV_THREAD:
1703 menu->current = mutt_previous_thread (CURHDR);
1706 case OP_MAIN_PREV_SUBTHREAD:
1707 menu->current = mutt_previous_subthread (CURHDR);
1711 if (menu->current < 0) {
1712 menu->current = menu->oldcurrent;
1713 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1714 mutt_error (_("No more threads."));
1717 mutt_error (_("You are on the first thread."));
1719 else if (menu->menu == MENU_PAGER) {
1720 op = OP_DISPLAY_MESSAGE;
1724 menu->redraw = REDRAW_MOTION;
1727 case OP_MAIN_PARENT_MESSAGE:
1732 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1733 menu->current = menu->oldcurrent;
1735 else if (menu->menu == MENU_PAGER) {
1736 op = OP_DISPLAY_MESSAGE;
1740 menu->redraw = REDRAW_MOTION;
1743 case OP_MAIN_SET_FLAG:
1744 case OP_MAIN_CLEAR_FLAG:
1750 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1752 menu->redraw = REDRAW_STATUS;
1754 menu->redraw |= REDRAW_INDEX;
1755 else if (option (OPTRESOLVE)) {
1756 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1757 menu->current = menu->oldcurrent;
1758 menu->redraw |= REDRAW_CURRENT;
1761 menu->redraw |= REDRAW_MOTION_RESYNCH;
1764 menu->redraw |= REDRAW_CURRENT;
1768 case OP_MAIN_COLLAPSE_THREAD:
1772 if ((Sort & SORT_MASK) != SORT_THREADS) {
1773 mutt_error (_("Threading is not enabled."));
1778 if (CURHDR->collapsed) {
1779 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1780 mutt_set_virtual (Context);
1781 if (option (OPTUNCOLLAPSEJUMP))
1782 menu->current = mutt_thread_next_unread (Context, CURHDR);
1784 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1785 menu->current = mutt_collapse_thread (Context, CURHDR);
1786 mutt_set_virtual (Context);
1789 mutt_error (_("Thread contains unread messages."));
1794 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1798 case OP_MAIN_COLLAPSE_ALL:
1802 if ((Sort & SORT_MASK) != SORT_THREADS) {
1803 mutt_error (_("Threading is not enabled."));
1810 THREAD *thread, *top;
1813 if (CURHDR->collapsed)
1814 final = mutt_uncollapse_thread (Context, CURHDR);
1815 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1816 final = mutt_collapse_thread (Context, CURHDR);
1818 final = CURHDR->virtual;
1820 base = Context->hdrs[Context->v2r[final]];
1822 top = Context->tree;
1823 Context->collapsed = !Context->collapsed;
1824 while ((thread = top) != NULL) {
1825 while (!thread->message)
1826 thread = thread->child;
1827 h = thread->message;
1829 if (h->collapsed != Context->collapsed) {
1831 mutt_uncollapse_thread (Context, h);
1832 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1833 mutt_collapse_thread (Context, h);
1838 mutt_set_virtual (Context);
1839 for (j = 0; j < Context->vcount; j++) {
1840 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1846 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1850 /* --------------------------------------------------------------------
1851 * These functions are invoked directly from the internal-pager
1854 case OP_BOUNCE_MESSAGE:
1859 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1862 case OP_CREATE_ALIAS:
1864 mutt_create_alias (Context
1865 && Context->vcount ? CURHDR->env : NULL, NULL);
1866 MAYBE_REDRAW (menu->redraw);
1867 menu->redraw |= REDRAW_CURRENT;
1872 mutt_query_menu (NULL, 0);
1873 MAYBE_REDRAW (menu->redraw);
1876 case OP_PURGE_MESSAGE:
1883 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1886 mutt_tag_set_flag (M_DELETE, 1);
1887 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1888 if (option (OPTDELETEUNTAG))
1889 mutt_tag_set_flag (M_TAG, 0);
1890 menu->redraw = REDRAW_INDEX;
1893 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1894 mutt_set_flag (Context, CURHDR, M_PURGED,
1895 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1896 if (option (OPTDELETEUNTAG))
1897 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1898 if (option (OPTRESOLVE)) {
1899 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1900 menu->current = menu->oldcurrent;
1901 menu->redraw = REDRAW_CURRENT;
1903 else if (menu->menu == MENU_PAGER) {
1904 op = OP_DISPLAY_MESSAGE;
1908 menu->redraw |= REDRAW_MOTION_RESYNCH;
1911 menu->redraw = REDRAW_CURRENT;
1913 menu->redraw |= REDRAW_STATUS;
1916 case OP_DELETE_THREAD:
1917 case OP_DELETE_SUBTHREAD:
1923 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1925 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1926 op == OP_DELETE_THREAD ? 0 : 1);
1929 if (option (OPTDELETEUNTAG))
1930 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1931 op == OP_DELETE_THREAD ? 0 : 1);
1932 if (option (OPTRESOLVE))
1933 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1934 menu->current = menu->oldcurrent;
1935 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1941 if (Context && Context->magic == M_NNTP) {
1942 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1943 ((NNTP_DATA *) Context->data)->group))
1944 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1949 case OP_DISPLAY_ADDRESS:
1953 mutt_display_address (CURHDR->env);
1956 case OP_ENTER_COMMAND:
1958 CurrentMenu = MENU_MAIN;
1959 mutt_enter_command ();
1960 mutt_check_rescore (Context);
1961 if (option (OPTFORCEREDRAWINDEX))
1962 menu->redraw = REDRAW_FULL;
1963 unset_option (OPTFORCEREDRAWINDEX);
1964 unset_option (OPTFORCEREDRAWPAGER);
1967 case OP_EDIT_MESSAGE:
1974 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1976 if (option (OPTPGPAUTODEC)
1977 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1978 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1979 mutt_edit_message (Context, tag ? NULL : CURHDR);
1980 menu->redraw = REDRAW_FULL;
1984 case OP_FORWARD_MESSAGE:
1990 if (option (OPTPGPAUTODEC) &&
1991 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1992 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1993 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
1994 menu->redraw = REDRAW_FULL;
1998 case OP_FORGET_PASSPHRASE:
1999 crypt_forget_passphrase ();
2002 case OP_GROUP_REPLY:
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 | SENDGROUPREPLY, NULL, NULL, Context,
2013 tag ? NULL : CURHDR);
2014 menu->redraw = REDRAW_FULL;
2023 if (option (OPTPGPAUTODEC) &&
2024 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2025 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2027 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2028 tag ? NULL : CURHDR);
2029 menu->redraw = REDRAW_FULL;
2035 ci_send_message (0, NULL, NULL, Context, NULL);
2036 menu->redraw = REDRAW_FULL;
2041 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2042 menu->redraw = REDRAW_FULL;
2046 case OP_EXTRACT_KEYS:
2049 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2050 menu->redraw = REDRAW_FULL;
2054 case OP_CHECK_TRADITIONAL:
2057 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2058 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2060 if (menu->menu == MENU_PAGER) {
2061 op = OP_DISPLAY_MESSAGE;
2070 mutt_pipe_message (tag ? NULL : CURHDR);
2071 /* in an IMAP folder index with imap_peek=no, piping could change
2072 * * new or old messages status to read. Redraw what's needed.
2074 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2075 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2077 MAYBE_REDRAW (menu->redraw);
2084 mutt_print_message (tag ? NULL : CURHDR);
2085 /* in an IMAP folder index with imap_peek=no, piping could change
2086 * * new or old messages status to read. Redraw what's needed.
2088 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2089 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2093 case OP_MAIN_READ_THREAD:
2094 case OP_MAIN_READ_SUBTHREAD:
2100 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2102 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2103 op == OP_MAIN_READ_THREAD ? 0 : 1);
2106 if (option (OPTRESOLVE)) {
2107 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2108 mutt_next_thread (CURHDR) :
2109 mutt_next_subthread (CURHDR))) == -1)
2110 menu->current = menu->oldcurrent;
2112 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2116 case OP_RECALL_MESSAGE:
2119 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2120 menu->redraw = REDRAW_FULL;
2130 for (j = 0; j < Context->vcount; j++) {
2131 if (Context->hdrs[Context->v2r[j]]->tagged)
2132 mutt_resend_message (NULL, Context,
2133 Context->hdrs[Context->v2r[j]]);
2137 mutt_resend_message (NULL, Context, CURHDR);
2139 menu->redraw = REDRAW_FULL;
2145 case OP_FORWARD_TO_GROUP:
2148 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2149 Context && Context->msgcount == 0) {
2150 mutt_error (_("There are no messages."));
2153 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2154 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2155 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2156 _("Reply by mail as poster prefers?")) !=
2158 if (Context && Context->magic == M_NNTP
2159 && !((NNTP_DATA *) Context->data)->allowed
2160 && query_quadoption (OPT_TOMODERATED,
2162 ("Posting to this group not allowed, may be moderated. Continue?"))
2166 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2169 if (op == OP_FOLLOWUP)
2170 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2171 tag ? NULL : CURHDR);
2173 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2174 tag ? NULL : CURHDR);
2176 menu->redraw = REDRAW_FULL;
2187 if (option (OPTPGPAUTODEC) &&
2188 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2189 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2191 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2192 menu->redraw = REDRAW_FULL;
2195 case OP_SHELL_ESCAPE:
2197 mutt_shell_escape ();
2198 MAYBE_REDRAW (menu->redraw);
2202 case OP_TAG_SUBTHREAD:
2206 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2207 op == OP_TAG_THREAD ? 0 : 1);
2210 if (option (OPTRESOLVE)) {
2211 menu->current = mutt_next_thread (CURHDR);
2213 if (menu->current == -1)
2214 menu->current = menu->oldcurrent;
2216 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2226 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2229 mutt_tag_set_flag (M_DELETE, 0);
2230 mutt_tag_set_flag (M_PURGED, 0);
2231 menu->redraw = REDRAW_INDEX;
2234 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2235 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2236 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2238 menu->redraw = REDRAW_MOTION_RESYNCH;
2241 menu->redraw = REDRAW_CURRENT;
2243 menu->redraw |= REDRAW_STATUS;
2246 case OP_UNDELETE_THREAD:
2247 case OP_UNDELETE_SUBTHREAD:
2253 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2255 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2256 op == OP_UNDELETE_THREAD ? 0 : 1)
2257 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2258 op == OP_UNDELETE_THREAD ? 0 : 1);
2261 if (option (OPTRESOLVE)) {
2262 if (op == OP_UNDELETE_THREAD)
2263 menu->current = mutt_next_thread (CURHDR);
2265 menu->current = mutt_next_subthread (CURHDR);
2267 if (menu->current == -1)
2268 menu->current = menu->oldcurrent;
2270 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2279 if (option (OPTFORCEBUFFYCHECK))
2282 menu->redraw = REDRAW_FULL;
2285 case OP_VIEW_ATTACHMENTS:
2288 mutt_view_attachments (CURHDR);
2289 if (CURHDR->attach_del)
2290 Context->changed = 1;
2291 menu->redraw = REDRAW_FULL;
2301 case OP_REBUILD_CACHE:
2302 mx_rebuild_cache ();
2305 case OP_SIDEBAR_SCROLL_UP:
2306 case OP_SIDEBAR_SCROLL_DOWN:
2307 case OP_SIDEBAR_NEXT:
2308 case OP_SIDEBAR_PREV:
2309 case OP_SIDEBAR_NEXT_NEW:
2310 case OP_SIDEBAR_PREV_NEW:
2311 sidebar_scroll (op);
2314 if (menu->menu == MENU_MAIN)
2315 km_error_key (MENU_MAIN);
2318 if (menu->menu == MENU_PAGER) {
2319 menu->menu = MENU_MAIN;
2320 menu->redraw = REDRAW_FULL;
2328 /* Close all open IMAP connections */
2331 /* Close all open NNTP connections */
2339 mutt_menuDestroy (&menu);
2343 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2350 for (color = ColorIndexList; color; color = color->next)
2351 if (mutt_pattern_exec
2352 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2353 curhdr->pair = color->pair;
2356 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];