2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * Parts were written/modified by:
6 * Nico Golde <nico@ngolde.de>
8 * This file is part of mutt-ng, see http://www.muttng.org/.
9 * It's licensed under the GNU General Public License,
10 * please see the file GPL in the top level source directory.
18 #include "mutt_curses.h"
20 #include "mutt_menu.h"
23 #include "recvattach.h"
35 #include "imap_private.h"
38 #include "mutt_crypt.h"
45 #include "mutt_sasl.h"
51 #include "lib/debug.h"
61 static const char *No_mailbox_is_open = N_("No mailbox is open.");
62 static const char *There_are_no_messages = N_("There are no messages.");
63 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
64 static const char *Function_not_permitted_in_attach_message_mode =
65 N_("Function not permitted in attach-message mode.");
66 static const char *No_visible = N_("No visible messages.");
68 #define CHECK_IN_MAILBOX if (!Context) \
71 mutt_error (_(No_mailbox_is_open)); \
75 #define CHECK_MSGCOUNT if (!Context) \
78 mutt_error(_(No_mailbox_is_open)); \
81 else if (!Context->msgcount) \
84 mutt_error(_(There_are_no_messages)); \
88 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
91 mutt_error(_(No_visible)); \
96 #define CHECK_READONLY if (Context->readonly) \
99 mutt_error(_(Mailbox_is_read_only)); \
103 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
106 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
110 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
111 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
112 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
114 extern const char *ReleaseDate;
115 extern size_t UngetCount;
117 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
120 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
121 int edgemsgno, reverse = Sort & SORT_REVERSE;
122 HEADER *h = Context->hdrs[Context->v2r[num]];
125 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
126 flag |= M_FORMAT_TREE; /* display the thread tree */
127 if (h->display_subject)
128 flag |= M_FORMAT_FORCESUBJ;
131 if (menu->top + menu->pagelen > menu->max)
132 edgemsgno = Context->v2r[menu->max - 1];
134 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
137 edgemsgno = Context->v2r[menu->top];
139 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
143 /* if no ancestor is visible on current screen, provisionally force
145 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
147 flag |= M_FORMAT_FORCESUBJ;
150 else if (tmp->message->virtual >= 0)
153 if (flag & M_FORMAT_FORCESUBJ) {
154 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
158 /* ...but if a previous sibling is available, don't force it */
159 if (reverse ? tmp->message->msgno >
160 edgemsgno : tmp->message->msgno < edgemsgno)
162 else if (tmp->message->virtual >= 0) {
163 flag &= ~M_FORMAT_FORCESUBJ;
171 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
174 int index_color (int index_no)
176 HEADER *h = Context->hdrs[Context->v2r[index_no]];
181 mutt_set_header_color (Context, h);
185 static int ci_next_undeleted (int msgno)
189 for (i = msgno + 1; i < Context->vcount; i++)
190 if (!Context->hdrs[Context->v2r[i]]->deleted)
195 static int ci_previous_undeleted (int msgno)
199 for (i = msgno - 1; i >= 0; i--)
200 if (!Context->hdrs[Context->v2r[i]]->deleted)
205 /* Return the index of the first new message, or failing that, the first
208 static int ci_first_message (void)
212 if (Context && Context->msgcount) {
213 for (i = 0; i < Context->vcount; i++) {
214 if (!Context->hdrs[Context->v2r[i]]->read &&
215 !Context->hdrs[Context->v2r[i]]->deleted) {
216 if (!Context->hdrs[Context->v2r[i]]->old)
225 /* If Sort is reverse and not threaded, the latest message is first.
226 * If Sort is threaded, the latest message is first iff exactly one
227 * of Sort and SortAux are reverse.
229 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
230 ((Sort & SORT_MASK) == SORT_THREADS &&
231 ((Sort ^ SortAux) & SORT_REVERSE)))
234 return (Context->vcount ? Context->vcount - 1 : 0);
239 /* This should be in mx.c, but it only gets used here. */
240 static int mx_toggle_write (CONTEXT * ctx)
246 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
251 if (ctx->dontwrite) {
253 mutt_message (_("Changes to folder will be written on folder exit."));
257 mutt_message (_("Changes to folder will not be written."));
263 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
264 int oldcount, int index_hint)
266 /* store pointers to the newly added messages */
267 HEADER **save_new = NULL;
270 /* take note of the current message */
272 if (menu->current < Context->vcount)
273 menu->oldcurrent = index_hint;
275 oldcount = 0; /* invalid message number! */
278 /* We are in a limited view. Check if the new message(s) satisfy
279 * the limit criteria. If they do, set their virtual msgno so that
280 * they will be visible in the limited view */
281 if (Context->pattern) {
282 #define THIS_BODY Context->hdrs[j]->content
283 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
284 if (mutt_pattern_exec
285 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
287 Context->hdrs[j]->virtual = Context->vcount;
288 Context->v2r[Context->vcount] = j;
289 Context->hdrs[j]->limited = 1;
292 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
298 /* save the list of new messages */
299 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
301 (HEADER **) mem_malloc (sizeof (HEADER *) *
302 (Context->msgcount - oldcount));
303 for (j = oldcount; j < Context->msgcount; j++)
304 save_new[j - oldcount] = Context->hdrs[j];
307 /* if the mailbox was reopened, need to rethread from scratch */
308 mutt_sort_headers (Context, (check == M_REOPENED));
310 /* uncollapse threads with new mail */
311 if ((Sort & SORT_MASK) == SORT_THREADS) {
312 if (check == M_REOPENED) {
315 Context->collapsed = 0;
317 for (h = Context->tree; h; h = h->next) {
318 for (j = h; !j->message; j = j->child);
319 mutt_uncollapse_thread (Context, j->message);
321 mutt_set_virtual (Context);
324 for (j = 0; j < Context->msgcount - oldcount; j++) {
327 for (k = 0; k < Context->msgcount; k++) {
328 HEADER *h = Context->hdrs[k];
330 if (h == save_new[j] && (!Context->pattern || h->limited))
331 mutt_uncollapse_thread (Context, h);
334 mem_free (&save_new);
335 mutt_set_virtual (Context);
341 /* restore the current message to the message it was pointing to */
342 for (j = 0; j < Context->vcount; j++) {
343 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
350 if (menu->current < 0)
351 menu->current = ci_first_message ();
354 static void resort_index (MUTTMENU * menu)
357 HEADER *current = CURHDR;
360 mutt_sort_headers (Context, 0);
361 /* Restore the current message */
363 for (i = 0; i < Context->vcount; i++) {
364 if (Context->hdrs[Context->v2r[i]] == current) {
370 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
371 menu->current = mutt_parent_message (Context, current);
373 if (menu->current < 0)
374 menu->current = ci_first_message ();
376 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
379 struct mapping_t IndexHelp[] = {
380 {N_("Quit"), OP_QUIT},
381 {N_("Del"), OP_DELETE},
382 {N_("Undel"), OP_UNDELETE},
383 {N_("Save"), OP_SAVE},
384 {N_("Mail"), OP_MAIL},
385 {N_("Reply"), OP_REPLY},
386 {N_("Group"), OP_GROUP_REPLY},
387 {N_("Help"), OP_HELP},
392 struct mapping_t IndexNewsHelp[] = {
393 {N_("Quit"), OP_QUIT},
394 {N_("Del"), OP_DELETE},
395 {N_("Undel"), OP_UNDELETE},
396 {N_("Save"), OP_SAVE},
397 {N_("Post"), OP_POST},
398 {N_("Followup"), OP_FOLLOWUP},
399 {N_("Catchup"), OP_CATCHUP},
400 {N_("Help"), OP_HELP},
405 /* This function handles the message index window as well as commands returned
406 * from the pager (MENU_PAGER).
408 int mutt_index_menu (void)
410 char buf[LONG_STRING], helpstr[SHORT_STRING];
413 int done = 0; /* controls when to exit the "event" loop */
415 int tag = 0; /* has the tag-prefix command been pressed? */
420 char *cp; /* temporary variable. */
421 int index_hint; /* used to restore cursor position */
422 int do_buffy_notify = 1;
423 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
424 int attach_msg = option (OPTATTACHMSG);
426 menu = mutt_new_menu ();
427 menu->menu = MENU_MAIN;
429 menu->pagelen = LINES - 3;
430 menu->make_entry = index_make_entry;
431 menu->color = index_color;
432 menu->current = ci_first_message ();
433 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
436 && (Context->magic ==
437 M_NNTP)) ? IndexNewsHelp :
442 buffy_check (1); /* force the buffy check after we enter the folder */
443 /* record folder we open to place sidebar indicator properly */
444 if (Context && Context->path)
445 sidebar_set_current (Context->path);
449 tag = 0; /* clear the tag-prefix */
451 menu->max = Context ? Context->vcount : 0;
452 oldcount = Context ? Context->msgcount : 0;
454 /* check if we need to resort the index because just about
455 * any 'op' below could do mutt_enter_command(), either here or
456 * from any new menu launched, and change $sort/$sort_aux
458 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
461 if (option (OPTREDRAWTREE) && Context && Context->msgcount
462 && (Sort & SORT_MASK) == SORT_THREADS) {
463 mutt_draw_tree (Context);
464 menu->redraw |= REDRAW_STATUS;
465 unset_option (OPTREDRAWTREE);
468 if (Context && !attach_msg) {
471 /* check for new mail in the mailbox. If nonzero, then something has
472 * changed about the file (either we got new mail or the file was
473 * modified underneath us.)
477 imap_allow_reopen (Context);
480 index_hint = (Context->vcount && menu->current >= 0
481 && menu->current < Context->vcount) ? CURHDR->index : 0;
483 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
484 if (!Context->path) {
485 /* fatal error occurred */
487 menu->redraw = REDRAW_FULL;
489 set_option (OPTSEARCHINVALID);
491 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
492 update_index (menu, Context, check, oldcount, index_hint);
494 /* notify the user of new mail */
495 if (check == M_REOPENED)
497 ("Mailbox was externally modified. Flags may be wrong."));
498 else if (check == M_NEW_MAIL) {
499 /* on new mail: redraw sidebar */
500 sidebar_draw (CurrentMenu);
501 mutt_message (_("New mail in this mailbox."));
503 if (option (OPTBEEPNEW))
506 else if (check == M_FLAGS)
507 mutt_message (_("Mailbox was externally modified."));
509 /* avoid the message being overwritten by buffy */
512 menu->redraw = REDRAW_FULL;
513 menu->max = Context->vcount;
515 set_option (OPTSEARCHINVALID);
521 imap_disallow_reopen (Context);
525 /* check for new mail in the incoming folders */
527 if ((newcount = buffy_check (0)) != oldcount) {
528 menu->redraw |= REDRAW_STATUS;
529 menu->redraw |= REDRAW_SIDEBAR;
531 if (do_buffy_notify) {
532 if (buffy_notify () && option (OPTBEEPNEW))
541 if (menu->redraw & REDRAW_SIDEBAR)
542 sidebar_draw (menu->menu);
543 if (menu->redraw & REDRAW_FULL) {
544 menu_redraw_full (menu);
545 sidebar_draw (menu->menu);
549 if (menu->menu == MENU_MAIN) {
550 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
551 menu_check_recenter (menu);
553 if (menu->redraw & REDRAW_INDEX) {
554 menu_redraw_index (menu);
555 menu->redraw |= REDRAW_STATUS;
557 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
558 menu_redraw_motion (menu);
559 else if (menu->redraw & REDRAW_CURRENT)
560 menu_redraw_current (menu);
563 if (menu->redraw & REDRAW_STATUS) {
565 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
567 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
568 SETCOLOR (MT_COLOR_STATUS);
569 BKGDSET (MT_COLOR_STATUS);
570 mutt_paddstr (COLS, buf);
571 SETCOLOR (MT_COLOR_NORMAL);
572 BKGDSET (MT_COLOR_NORMAL);
573 sidebar_set_buffystats (Context);
574 menu->redraw &= ~REDRAW_STATUS;
575 if (option (OPTXTERMSETTITLES)) {
576 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
577 mutt_xterm_set_title (buf);
578 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
579 mutt_xterm_set_icon (buf);
584 if (menu->current < menu->max)
585 menu->oldcurrent = menu->current;
587 menu->oldcurrent = -1;
589 if (option (OPTARROWCURSOR))
590 move (menu->current - menu->top + menu->offset, 2);
591 else if (option (OPTBRAILLEFRIENDLY))
592 move (menu->current - menu->top + menu->offset, 0);
594 move (menu->current - menu->top + menu->offset, COLS - 1);
597 op = km_dokey (MENU_MAIN);
599 debug_print (4, ("Got op %d\n", op));
601 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
604 mutt_resize_screen ();
605 menu->redraw = REDRAW_FULL;
606 menu->menu = MENU_MAIN;
608 menu->top = 0; /* so we scroll the right amount */
610 * force a real complete redraw. clrtobot() doesn't seem to be able
611 * to handle every case without this.
613 clearok (stdscr, TRUE);
619 continue; /* either user abort or timeout */
623 /* special handling for the tag-prefix function */
624 if (op == OP_TAG_PREFIX) {
626 mutt_error (_("No mailbox is open."));
631 if (!Context->tagged) {
632 mutt_error (_("No tagged messages."));
638 /* give visual indication that the next command is a tag- command */
639 mvaddstr (LINES - 1, 0, "tag-");
642 /* get the real command */
643 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
644 /* abort tag sequence */
645 CLEARLINE (LINES - 1);
649 else if (option (OPTAUTOTAG) && Context && Context->tagged)
652 if (op == OP_TAG_PREFIX_COND) {
654 mutt_error (_("No mailbox is open."));
659 if (!Context->tagged) {
662 while (UngetCount > 0) {
664 if (tmp.op == OP_END_COND)
667 mutt_message (_("Nothing to do."));
673 /* give visual indication that the next command is a tag- command */
674 mvaddstr (LINES - 1, 0, "tag-");
677 /* get the real command */
678 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
679 /* abort tag sequence */
680 CLEARLINE (LINES - 1);
688 if (menu->current < menu->max)
689 menu->oldcurrent = menu->current;
691 menu->oldcurrent = -1;
693 mutt_curs_set (1); /* fallback from the pager */
697 unset_option (OPTNEWS); /* for any case */
702 /* ----------------------------------------------------------------------
707 menu_bottom_page (menu);
710 menu_first_entry (menu);
713 menu_middle_page (menu);
719 menu_half_down (menu);
722 menu_next_line (menu);
725 menu_prev_line (menu);
728 menu_next_page (menu);
731 menu_prev_page (menu);
734 menu_last_entry (menu);
737 menu_top_page (menu);
740 menu_current_top (menu);
742 case OP_CURRENT_MIDDLE:
743 menu_current_middle (menu);
745 case OP_CURRENT_BOTTOM:
746 menu_current_bottom (menu);
753 if (Context->magic == M_NNTP) {
756 if (op == OP_GET_MESSAGE) {
758 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0)
763 LIST *ref = CURHDR->env->references;
766 mutt_error (_("Article has no parent reference!"));
770 strfcpy (buf, ref->data, sizeof (buf));
772 if (!Context->id_hash)
773 Context->id_hash = mutt_make_id_hash (Context);
774 if ((h = hash_find (Context->id_hash, buf))) {
775 if (h->virtual != -1) {
776 menu->current = h->virtual;
777 menu->redraw = REDRAW_MOTION_RESYNCH;
779 else if (h->collapsed) {
780 mutt_uncollapse_thread (Context, h);
781 mutt_set_virtual (Context);
782 menu->current = h->virtual;
783 menu->redraw = REDRAW_MOTION_RESYNCH;
786 mutt_error (_("Message not visible in limited view."));
789 if (nntp_check_msgid (Context, buf) == 0) {
790 h = Context->hdrs[Context->msgcount - 1];
791 mutt_sort_headers (Context, 0);
792 menu->current = h->virtual;
793 menu->redraw = REDRAW_FULL;
796 mutt_error (_("Article %s not found on server"), buf);
801 case OP_GET_CHILDREN:
802 case OP_RECONSTRUCT_THREAD:
804 if (Context->magic == M_NNTP) {
806 int old = CURHDR->index, i;
808 if (!CURHDR->env->message_id) {
809 mutt_error (_("No Message-Id. Unable to perform operation"));
814 if (!Context->id_hash)
815 Context->id_hash = mutt_make_id_hash (Context);
816 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
818 if (op == OP_RECONSTRUCT_THREAD) {
819 LIST *ref = CURHDR->env->references;
822 nntp_check_msgid (Context, ref->data);
823 /* the last msgid in References is the root message */
825 strfcpy (buf, ref->data, sizeof (buf));
829 mutt_message (_("Check for children of message..."));
831 if (nntp_check_children (Context, buf) == 0) {
832 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
833 h = hash_find (Context->id_hash, buf);
834 /* if the root message was retrieved, move to it */
836 menu->current = h->virtual;
837 else /* try to restore old position */
838 for (i = 0; i < Context->msgcount; i++)
839 if (Context->hdrs[i]->index == old) {
840 menu->current = Context->hdrs[i]->virtual;
841 /* As an added courtesy, recenter the menu
842 * with the current entry at the middle of the screen */
843 menu_check_recenter (menu);
844 menu_current_middle (menu);
847 menu->redraw = REDRAW_FULL;
857 if (isdigit (LastKey))
858 mutt_ungetch (LastKey, 0);
860 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
864 if (!isdigit ((unsigned char) buf[0])) {
865 mutt_error (_("Argument must be a message number."));
871 if (i > 0 && i <= Context->msgcount) {
872 for (j = i - 1; j < Context->msgcount; j++) {
873 if (Context->hdrs[j]->virtual != -1)
876 if (j >= Context->msgcount) {
877 for (j = i - 2; j >= 0; j--) {
878 if (Context->hdrs[j]->virtual != -1)
884 menu->current = Context->hdrs[j]->virtual;
885 if (menu->menu == MENU_PAGER) {
886 op = OP_DISPLAY_MESSAGE;
890 menu->redraw = REDRAW_MOTION;
893 mutt_error (_("That message is not visible."));
896 mutt_error (_("Invalid message number."));
900 /* --------------------------------------------------------------------
901 * `index' specific commands
904 case OP_MAIN_DELETE_PATTERN:
910 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
913 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
914 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
918 case OP_MAIN_FETCH_MAIL:
922 menu->redraw = REDRAW_FULL;
928 mutt_help (MENU_MAIN);
929 menu->redraw = REDRAW_FULL;
932 case OP_MAIN_SHOW_LIMIT:
934 if (!Context->pattern)
935 mutt_message (_("No limit pattern is in effect."));
940 /* i18n: ask for a limit to apply */
941 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
942 mutt_message ("%s", buf);
950 menu->oldcurrent = (Context->vcount && menu->current >= 0
952 Context->vcount) ? CURHDR->index : -1;
953 if (op == OP_TOGGLE_READ) {
954 char buf[LONG_STRING];
956 if (!Context->pattern
957 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
958 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
959 Context->pattern ? Context->pattern : ".*");
960 set_option (OPTHIDEREAD);
963 strfcpy (buf, Context->pattern + 8, sizeof (buf));
964 if (!*buf || strncmp (buf, ".*", 2) == 0)
965 snprintf (buf, sizeof (buf), "~A");
966 unset_option (OPTHIDEREAD);
968 mem_free (&Context->pattern);
969 Context->pattern = str_dup (buf);
971 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
972 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
974 if (menu->oldcurrent >= 0) {
975 /* try to find what used to be the current message */
977 for (i = 0; i < Context->vcount; i++)
978 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
982 if (menu->current < 0)
987 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
988 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
989 mutt_draw_tree (Context);
990 menu->redraw = REDRAW_FULL;
1002 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1005 oldcount = Context ? Context->msgcount : 0;
1008 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1011 if (check == M_NEW_MAIL || check == M_REOPENED)
1012 update_index (menu, Context, check, oldcount, index_hint);
1014 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1015 set_option (OPTSEARCHINVALID);
1022 clearok (stdscr, TRUE);
1023 menu->redraw = REDRAW_FULL;
1027 case OP_SEARCH_REVERSE:
1028 case OP_SEARCH_NEXT:
1029 case OP_SEARCH_OPPOSITE:
1033 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1034 menu->current = menu->oldcurrent;
1036 menu->redraw = REDRAW_MOTION;
1040 case OP_SORT_REVERSE:
1042 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1043 if (Context && Context->msgcount) {
1044 resort_index (menu);
1045 set_option (OPTSEARCHINVALID);
1054 if (tag && !option (OPTAUTOTAG)) {
1055 for (j = 0; j < Context->vcount; j++)
1056 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1057 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1060 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1061 Context->last_tag = CURHDR->tagged ? CURHDR :
1062 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1063 ? NULL : Context->last_tag);
1064 menu->redraw = REDRAW_STATUS;
1065 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1067 menu->redraw |= REDRAW_MOTION_RESYNCH;
1070 menu->redraw |= REDRAW_CURRENT;
1074 case OP_MAIN_TAG_PATTERN:
1078 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1079 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1082 case OP_MAIN_UNDELETE_PATTERN:
1088 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1090 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1092 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1095 case OP_MAIN_UNTAG_PATTERN:
1099 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1100 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1103 /* --------------------------------------------------------------------
1104 * The following operations can be performed inside of the pager.
1108 case OP_MAIN_IMAP_FETCH:
1109 if (Context->magic == M_IMAP)
1110 imap_check_mailbox (Context, &index_hint, 1);
1114 case OP_MAIN_SYNC_FOLDER:
1116 if (Context && !Context->msgcount)
1123 int oldvcount = Context->vcount;
1124 int oldcount = Context->msgcount;
1128 /* calculate the number of messages _above_ the cursor,
1129 * so we can keep the cursor on the current message
1131 for (j = 0; j <= menu->current; j++) {
1132 if (Context->hdrs[Context->v2r[j]]->deleted)
1136 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1137 if (Context->vcount != oldvcount)
1138 menu->current -= dcount;
1139 set_option (OPTSEARCHINVALID);
1141 else if (check == M_NEW_MAIL || check == M_REOPENED)
1142 update_index (menu, Context, check, oldcount, index_hint);
1145 * do a sanity check even if mx_sync_mailbox failed.
1148 if (menu->current < 0 || menu->current >= Context->vcount)
1149 menu->current = ci_first_message ();
1152 /* check for a fatal error, or all messages deleted */
1154 mem_free (&Context);
1156 /* if we were in the pager, redisplay the message */
1157 if (menu->menu == MENU_PAGER) {
1158 op = OP_DISPLAY_MESSAGE;
1162 menu->redraw = REDRAW_FULL;
1165 case OP_SIDEBAR_OPEN:
1166 case OP_MAIN_CHANGE_FOLDER:
1167 case OP_MAIN_CHANGE_FOLDER_READONLY:
1169 case OP_MAIN_CHANGE_GROUP:
1170 case OP_MAIN_CHANGE_GROUP_READONLY:
1172 if (attach_msg || option (OPTREADONLY) ||
1174 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1176 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1182 cp = _("Open mailbox in read-only mode");
1184 cp = _("Open mailbox");
1188 unset_option (OPTNEWS);
1189 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1190 set_option (OPTNEWS);
1191 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1194 cp = _("Open newsgroup in read-only mode");
1196 cp = _("Open newsgroup");
1197 nntp_buffy (buf, sizeof (buf));
1202 if (Context && Context->path)
1203 strncpy (buf, Context->path, sizeof (buf));
1204 if (op != OP_SIDEBAR_OPEN)
1205 buffy_next (buf, sizeof (buf));
1208 if (op == OP_SIDEBAR_OPEN) {
1209 strncpy (buf, NONULL(sidebar_get_current ()), sizeof (buf));
1211 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1215 CLEARLINE (LINES - 1);
1220 if (option (OPTNEWS)) {
1221 unset_option (OPTNEWS);
1222 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1226 mutt_expand_path (buf, sizeof (buf));
1227 if (mx_get_magic (buf) <= 0) {
1228 mutt_error (_("%s is not a mailbox."), buf);
1231 str_replace (&CurrentFolder, buf);
1236 #ifdef USE_COMPRESSED
1237 if (Context->compressinfo && Context->realpath)
1238 str_replace (&LastFolder, Context->realpath);
1242 str_replace (&LastFolder, Context->path);
1243 oldcount = Context ? Context->msgcount : 0;
1245 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1246 if (check == M_NEW_MAIL || check == M_REOPENED)
1247 update_index (menu, Context, check, oldcount, index_hint);
1249 set_option (OPTSEARCHINVALID);
1250 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1253 mem_free (&Context);
1258 /* Set CurrentMenu to MENU_MAIN before executing any folder
1259 * hooks so that all the index menu functions are available to
1263 CurrentMenu = MENU_MAIN;
1264 mutt_folder_hook (buf);
1266 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1267 menu->current = ci_first_message ();
1271 sidebar_set_current (buf);
1274 /* buffy_check() must be done with mail-reader mode! */
1275 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1277 && (Context->magic ==
1278 M_NNTP)) ? IndexNewsHelp :
1281 mutt_clear_error ();
1282 buffy_check (1); /* force the buffy check after we have changed
1284 menu->redraw = REDRAW_FULL;
1285 set_option (OPTSEARCHINVALID);
1288 case OP_DISPLAY_MESSAGE:
1289 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1294 * toggle the weeding of headers so that a user can press the key
1295 * again while reading the message.
1297 if (op == OP_DISPLAY_HEADERS)
1298 toggle_option (OPTWEED);
1300 unset_option (OPTNEEDRESORT);
1302 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1303 mutt_uncollapse_thread (Context, CURHDR);
1304 mutt_set_virtual (Context);
1305 if (option (OPTUNCOLLAPSEJUMP))
1306 menu->current = mutt_thread_next_unread (Context, CURHDR);
1309 if (option (OPTPGPAUTODEC) &&
1310 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1311 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1313 if ((op = mutt_display_message (CURHDR)) == -1) {
1314 unset_option (OPTNEEDRESORT);
1318 menu->menu = MENU_PAGER;
1319 menu->oldcurrent = menu->current;
1325 if (menu->menu == MENU_MAIN && attach_msg) {
1330 if ((menu->menu == MENU_MAIN)
1331 && (query_quadoption (OPT_QUIT,
1332 _("Exit Mutt-ng without saving?")) == M_YES))
1335 mx_fastclose_mailbox (Context);
1336 mem_free (&Context);
1347 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1348 /* if we were in the pager, redisplay the message */
1349 if (menu->menu == MENU_PAGER) {
1350 op = OP_DISPLAY_MESSAGE;
1354 menu->redraw = REDRAW_CURRENT;
1357 case OP_MAIN_BREAK_THREAD:
1363 if ((Sort & SORT_MASK) != SORT_THREADS)
1364 mutt_error (_("Threading is not enabled."));
1368 HEADER *oldcur = CURHDR;
1370 mutt_break_thread (CURHDR);
1371 mutt_sort_headers (Context, 1);
1372 menu->current = oldcur->virtual;
1375 Context->changed = 1;
1376 mutt_message _("Thread broken");
1378 if (menu->menu == MENU_PAGER) {
1379 op = OP_DISPLAY_MESSAGE;
1383 menu->redraw |= REDRAW_INDEX;
1387 case OP_MAIN_LINK_THREADS:
1393 if ((Sort & SORT_MASK) != SORT_THREADS)
1394 mutt_error (_("Threading is not enabled."));
1396 else if (!CURHDR->env->message_id)
1397 mutt_error (_("No Message-ID: header available to link thread"));
1399 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1400 mutt_error (_("First, please tag a message to be linked here"));
1403 HEADER *oldcur = CURHDR;
1405 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1407 mutt_sort_headers (Context, 1);
1408 menu->current = oldcur->virtual;
1410 Context->changed = 1;
1411 mutt_message _("Threads linked");
1414 mutt_error (_("No thread linked"));
1417 if (menu->menu == MENU_PAGER) {
1418 op = OP_DISPLAY_MESSAGE;
1422 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1425 case OP_MAIN_NEXT_UNDELETED:
1429 if (menu->current >= Context->vcount - 1) {
1430 if (menu->menu == MENU_MAIN)
1431 mutt_error (_("You are on the last message."));
1435 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1436 menu->current = menu->oldcurrent;
1437 if (menu->menu == MENU_MAIN)
1438 mutt_error (_("No undeleted messages."));
1440 else if (menu->menu == MENU_PAGER) {
1441 op = OP_DISPLAY_MESSAGE;
1445 menu->redraw = REDRAW_MOTION;
1452 if (menu->current >= Context->vcount - 1) {
1453 if (menu->menu == MENU_MAIN)
1454 mutt_error (_("You are on the last message."));
1459 if (menu->menu == MENU_PAGER) {
1460 op = OP_DISPLAY_MESSAGE;
1464 menu->redraw = REDRAW_MOTION;
1467 case OP_MAIN_PREV_UNDELETED:
1471 if (menu->current < 1) {
1472 mutt_error (_("You are on the first message."));
1476 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1477 menu->current = menu->oldcurrent;
1478 if (menu->menu == MENU_MAIN)
1479 mutt_error (_("No undeleted messages."));
1481 else if (menu->menu == MENU_PAGER) {
1482 op = OP_DISPLAY_MESSAGE;
1486 menu->redraw = REDRAW_MOTION;
1493 if (menu->current < 1) {
1494 if (menu->menu == MENU_MAIN)
1495 mutt_error (_("You are on the first message."));
1500 if (menu->menu == MENU_PAGER) {
1501 op = OP_DISPLAY_MESSAGE;
1505 menu->redraw = REDRAW_MOTION;
1508 case OP_DECRYPT_COPY:
1509 case OP_DECRYPT_SAVE:
1513 case OP_COPY_MESSAGE:
1515 case OP_DECODE_COPY:
1516 case OP_DECODE_SAVE:
1519 if (mutt_save_message (tag ? NULL : CURHDR,
1520 (op == OP_DECRYPT_SAVE) ||
1521 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1522 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1523 (op == OP_DECRYPT_SAVE)
1524 || (op == OP_DECRYPT_COPY)
1525 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1532 menu->redraw |= REDRAW_INDEX;
1533 else if (option (OPTRESOLVE)) {
1534 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1535 menu->current = menu->oldcurrent;
1536 menu->redraw |= REDRAW_CURRENT;
1539 menu->redraw |= REDRAW_MOTION_RESYNCH;
1542 menu->redraw |= REDRAW_CURRENT;
1546 case OP_MAIN_NEXT_NEW:
1547 case OP_MAIN_NEXT_UNREAD:
1548 case OP_MAIN_PREV_NEW:
1549 case OP_MAIN_PREV_UNREAD:
1550 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1551 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1554 int first_unread = -1;
1562 for (j = 0; j != Context->vcount; j++) {
1563 #define CURHDRi Context->hdrs[Context->v2r[i]]
1564 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1565 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1567 if (i > Context->vcount - 1) {
1568 mutt_message _("Search wrapped to top.");
1576 mutt_message _("Search wrapped to bottom.");
1578 i = Context->vcount - 1;
1582 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1583 if (UNREAD (CURHDRi) && first_unread == -1)
1585 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1588 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1589 if (first_unread == -1)
1591 if ((!CURHDRi->old) && first_new == -1)
1595 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1598 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1599 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1600 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1605 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1606 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1607 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1609 menu->current = first_new;
1610 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1611 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1612 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1613 && first_unread != -1)
1614 menu->current = first_unread;
1616 if (menu->current == -1) {
1617 menu->current = menu->oldcurrent;
1618 mutt_error ("%s%s.",
1619 (op == OP_MAIN_NEXT_NEW
1621 OP_MAIN_PREV_NEW) ? _("No new messages") :
1622 _("No unread messages"),
1623 Context->pattern ? _(" in this limited view") : "");
1625 else if (menu->menu == MENU_PAGER) {
1626 op = OP_DISPLAY_MESSAGE;
1630 menu->redraw = REDRAW_MOTION;
1633 case OP_FLAG_MESSAGE:
1639 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1642 for (j = 0; j < Context->vcount; j++) {
1643 if (Context->hdrs[Context->v2r[j]]->tagged)
1644 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1645 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1648 menu->redraw |= REDRAW_INDEX;
1651 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1652 if (option (OPTRESOLVE)) {
1653 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1654 menu->current = menu->oldcurrent;
1655 menu->redraw = REDRAW_CURRENT;
1658 menu->redraw = REDRAW_MOTION_RESYNCH;
1661 menu->redraw = REDRAW_CURRENT;
1663 menu->redraw |= REDRAW_STATUS;
1672 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1675 for (j = 0; j < Context->vcount; j++) {
1676 if (Context->hdrs[Context->v2r[j]]->tagged) {
1677 if (Context->hdrs[Context->v2r[j]]->read ||
1678 Context->hdrs[Context->v2r[j]]->old)
1679 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1682 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1686 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1689 if (CURHDR->read || CURHDR->old)
1690 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1692 mutt_set_flag (Context, CURHDR, M_READ, 1);
1694 if (option (OPTRESOLVE)) {
1695 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1696 menu->current = menu->oldcurrent;
1697 menu->redraw = REDRAW_CURRENT;
1700 menu->redraw = REDRAW_MOTION_RESYNCH;
1703 menu->redraw = REDRAW_CURRENT;
1704 menu->redraw |= REDRAW_STATUS;
1708 case OP_TOGGLE_WRITE:
1711 if (mx_toggle_write (Context) == 0)
1712 menu->redraw |= REDRAW_STATUS;
1715 case OP_MAIN_NEXT_THREAD:
1716 case OP_MAIN_NEXT_SUBTHREAD:
1717 case OP_MAIN_PREV_THREAD:
1718 case OP_MAIN_PREV_SUBTHREAD:
1723 case OP_MAIN_NEXT_THREAD:
1724 menu->current = mutt_next_thread (CURHDR);
1727 case OP_MAIN_NEXT_SUBTHREAD:
1728 menu->current = mutt_next_subthread (CURHDR);
1731 case OP_MAIN_PREV_THREAD:
1732 menu->current = mutt_previous_thread (CURHDR);
1735 case OP_MAIN_PREV_SUBTHREAD:
1736 menu->current = mutt_previous_subthread (CURHDR);
1740 if (menu->current < 0) {
1741 menu->current = menu->oldcurrent;
1742 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1743 mutt_error (_("No more threads."));
1746 mutt_error (_("You are on the first thread."));
1748 else if (menu->menu == MENU_PAGER) {
1749 op = OP_DISPLAY_MESSAGE;
1753 menu->redraw = REDRAW_MOTION;
1756 case OP_MAIN_PARENT_MESSAGE:
1761 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1762 menu->current = menu->oldcurrent;
1764 else if (menu->menu == MENU_PAGER) {
1765 op = OP_DISPLAY_MESSAGE;
1769 menu->redraw = REDRAW_MOTION;
1772 case OP_MAIN_SET_FLAG:
1773 case OP_MAIN_CLEAR_FLAG:
1779 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1781 menu->redraw = REDRAW_STATUS;
1783 menu->redraw |= REDRAW_INDEX;
1784 else if (option (OPTRESOLVE)) {
1785 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1786 menu->current = menu->oldcurrent;
1787 menu->redraw |= REDRAW_CURRENT;
1790 menu->redraw |= REDRAW_MOTION_RESYNCH;
1793 menu->redraw |= REDRAW_CURRENT;
1797 case OP_MAIN_COLLAPSE_THREAD:
1801 if ((Sort & SORT_MASK) != SORT_THREADS) {
1802 mutt_error (_("Threading is not enabled."));
1807 if (CURHDR->collapsed) {
1808 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1809 mutt_set_virtual (Context);
1810 if (option (OPTUNCOLLAPSEJUMP))
1811 menu->current = mutt_thread_next_unread (Context, CURHDR);
1813 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1814 menu->current = mutt_collapse_thread (Context, CURHDR);
1815 mutt_set_virtual (Context);
1818 mutt_error (_("Thread contains unread messages."));
1823 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1827 case OP_MAIN_COLLAPSE_ALL:
1831 if ((Sort & SORT_MASK) != SORT_THREADS) {
1832 mutt_error (_("Threading is not enabled."));
1839 THREAD *thread, *top;
1842 if (CURHDR->collapsed)
1843 final = mutt_uncollapse_thread (Context, CURHDR);
1844 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1845 final = mutt_collapse_thread (Context, CURHDR);
1847 final = CURHDR->virtual;
1849 base = Context->hdrs[Context->v2r[final]];
1851 top = Context->tree;
1852 Context->collapsed = !Context->collapsed;
1853 while ((thread = top) != NULL) {
1854 while (!thread->message)
1855 thread = thread->child;
1856 h = thread->message;
1858 if (h->collapsed != Context->collapsed) {
1860 mutt_uncollapse_thread (Context, h);
1861 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1862 mutt_collapse_thread (Context, h);
1867 mutt_set_virtual (Context);
1868 for (j = 0; j < Context->vcount; j++) {
1869 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1875 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1879 /* --------------------------------------------------------------------
1880 * These functions are invoked directly from the internal-pager
1883 case OP_BOUNCE_MESSAGE:
1888 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1891 case OP_CREATE_ALIAS:
1893 mutt_create_alias (Context
1894 && Context->vcount ? CURHDR->env : NULL, NULL);
1895 MAYBE_REDRAW (menu->redraw);
1896 menu->redraw |= REDRAW_CURRENT;
1901 mutt_query_menu (NULL, 0);
1902 MAYBE_REDRAW (menu->redraw);
1905 case OP_PURGE_MESSAGE:
1912 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1915 mutt_tag_set_flag (M_DELETE, 1);
1916 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1917 if (option (OPTDELETEUNTAG))
1918 mutt_tag_set_flag (M_TAG, 0);
1919 menu->redraw = REDRAW_INDEX;
1922 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1923 mutt_set_flag (Context, CURHDR, M_PURGED,
1924 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1925 if (option (OPTDELETEUNTAG))
1926 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1927 if (option (OPTRESOLVE)) {
1928 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1929 menu->current = menu->oldcurrent;
1930 menu->redraw = REDRAW_CURRENT;
1932 else if (menu->menu == MENU_PAGER) {
1933 op = OP_DISPLAY_MESSAGE;
1937 menu->redraw |= REDRAW_MOTION_RESYNCH;
1940 menu->redraw = REDRAW_CURRENT;
1942 menu->redraw |= REDRAW_STATUS;
1945 case OP_DELETE_THREAD:
1946 case OP_DELETE_SUBTHREAD:
1952 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1954 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1955 op == OP_DELETE_THREAD ? 0 : 1);
1958 if (option (OPTDELETEUNTAG))
1959 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1960 op == OP_DELETE_THREAD ? 0 : 1);
1961 if (option (OPTRESOLVE))
1962 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1963 menu->current = menu->oldcurrent;
1964 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1970 if (Context && Context->magic == M_NNTP) {
1971 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1972 ((NNTP_DATA *) Context->data)->group))
1973 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1978 case OP_DISPLAY_ADDRESS:
1982 mutt_display_address (CURHDR->env);
1985 case OP_ENTER_COMMAND:
1987 CurrentMenu = MENU_MAIN;
1988 mutt_enter_command ();
1989 mutt_check_rescore (Context);
1990 if (option (OPTFORCEREDRAWINDEX))
1991 menu->redraw = REDRAW_FULL;
1992 unset_option (OPTFORCEREDRAWINDEX);
1993 unset_option (OPTFORCEREDRAWPAGER);
1996 case OP_EDIT_MESSAGE:
2003 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
2005 if (option (OPTPGPAUTODEC)
2006 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2007 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2008 mutt_edit_message (Context, tag ? NULL : CURHDR);
2009 menu->redraw = REDRAW_FULL;
2013 case OP_FORWARD_MESSAGE:
2019 if (option (OPTPGPAUTODEC) &&
2020 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2021 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2022 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2023 menu->redraw = REDRAW_FULL;
2027 case OP_FORGET_PASSPHRASE:
2028 crypt_forget_passphrase ();
2031 case OP_GROUP_REPLY:
2037 if (option (OPTPGPAUTODEC) &&
2038 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2039 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2041 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2042 tag ? NULL : CURHDR);
2043 menu->redraw = REDRAW_FULL;
2052 if (option (OPTPGPAUTODEC) &&
2053 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2054 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2056 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2057 tag ? NULL : CURHDR);
2058 menu->redraw = REDRAW_FULL;
2064 ci_send_message (0, NULL, NULL, Context, NULL);
2065 menu->redraw = REDRAW_FULL;
2069 if (!(WithCrypto & APPLICATION_PGP))
2072 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2073 menu->redraw = REDRAW_FULL;
2077 case OP_EXTRACT_KEYS:
2082 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2083 menu->redraw = REDRAW_FULL;
2087 case OP_CHECK_TRADITIONAL:
2088 if (!(WithCrypto & APPLICATION_PGP))
2092 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2093 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2095 if (menu->menu == MENU_PAGER) {
2096 op = OP_DISPLAY_MESSAGE;
2105 mutt_pipe_message (tag ? NULL : CURHDR);
2106 MAYBE_REDRAW (menu->redraw);
2113 mutt_print_message (tag ? NULL : CURHDR);
2116 case OP_MAIN_READ_THREAD:
2117 case OP_MAIN_READ_SUBTHREAD:
2123 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2125 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2126 op == OP_MAIN_READ_THREAD ? 0 : 1);
2129 if (option (OPTRESOLVE)) {
2130 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2131 mutt_next_thread (CURHDR) :
2132 mutt_next_subthread (CURHDR))) == -1)
2133 menu->current = menu->oldcurrent;
2135 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2139 case OP_RECALL_MESSAGE:
2142 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2143 menu->redraw = REDRAW_FULL;
2153 for (j = 0; j < Context->vcount; j++) {
2154 if (Context->hdrs[Context->v2r[j]]->tagged)
2155 mutt_resend_message (NULL, Context,
2156 Context->hdrs[Context->v2r[j]]);
2160 mutt_resend_message (NULL, Context, CURHDR);
2162 menu->redraw = REDRAW_FULL;
2168 case OP_FORWARD_TO_GROUP:
2171 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2172 Context && Context->msgcount == 0) {
2173 mutt_error (_("There are no messages."));
2176 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2177 str_casecmp (CURHDR->env->followup_to, "poster") ||
2178 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2179 _("Reply by mail as poster prefers?")) !=
2181 if (Context && Context->magic == M_NNTP
2182 && !((NNTP_DATA *) Context->data)->allowed
2183 && query_quadoption (OPT_TOMODERATED,
2185 ("Posting to this group not allowed, may be moderated. Continue?"))
2189 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2192 if (op == OP_FOLLOWUP)
2193 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2194 tag ? NULL : CURHDR);
2196 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2197 tag ? NULL : CURHDR);
2199 menu->redraw = REDRAW_FULL;
2210 if (option (OPTPGPAUTODEC) &&
2211 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2212 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2214 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2215 menu->redraw = REDRAW_FULL;
2218 case OP_SHELL_ESCAPE:
2220 mutt_shell_escape ();
2221 MAYBE_REDRAW (menu->redraw);
2225 case OP_TAG_SUBTHREAD:
2229 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2230 op == OP_TAG_THREAD ? 0 : 1);
2233 if (option (OPTRESOLVE)) {
2234 menu->current = mutt_next_thread (CURHDR);
2236 if (menu->current == -1)
2237 menu->current = menu->oldcurrent;
2239 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2249 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2252 mutt_tag_set_flag (M_DELETE, 0);
2253 mutt_tag_set_flag (M_PURGED, 0);
2254 menu->redraw = REDRAW_INDEX;
2257 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2258 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2259 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2261 menu->redraw = REDRAW_MOTION_RESYNCH;
2264 menu->redraw = REDRAW_CURRENT;
2266 menu->redraw |= REDRAW_STATUS;
2269 case OP_UNDELETE_THREAD:
2270 case OP_UNDELETE_SUBTHREAD:
2276 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2278 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2279 op == OP_UNDELETE_THREAD ? 0 : 1)
2280 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2281 op == OP_UNDELETE_THREAD ? 0 : 1);
2284 if (option (OPTRESOLVE)) {
2285 if (op == OP_UNDELETE_THREAD)
2286 menu->current = mutt_next_thread (CURHDR);
2288 menu->current = mutt_next_subthread (CURHDR);
2290 if (menu->current == -1)
2291 menu->current = menu->oldcurrent;
2293 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2302 if (option (OPTFORCEBUFFYCHECK))
2305 menu->redraw = REDRAW_FULL;
2308 case OP_VIEW_ATTACHMENTS:
2311 mutt_view_attachments (CURHDR);
2312 if (CURHDR->attach_del)
2313 Context->changed = 1;
2314 menu->redraw = REDRAW_FULL;
2324 case OP_SIDEBAR_SCROLL_UP:
2325 case OP_SIDEBAR_SCROLL_DOWN:
2326 case OP_SIDEBAR_NEXT:
2327 case OP_SIDEBAR_PREV:
2328 case OP_SIDEBAR_NEXT_NEW:
2329 case OP_SIDEBAR_PREV_NEW:
2330 sidebar_scroll (op, menu->menu);
2333 if (menu->menu == MENU_MAIN)
2334 km_error_key (MENU_MAIN);
2337 if (menu->menu == MENU_PAGER) {
2338 menu->menu = MENU_MAIN;
2339 menu->redraw = REDRAW_FULL;
2341 set_option (OPTWEED); /* turn header weeding back on. */
2351 /* Close all open IMAP connections */
2355 /* Close all open NNTP connections */
2363 mutt_menuDestroy (&menu);
2367 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2374 for (color = ColorIndexList; color; color = color->next)
2375 if (mutt_pattern_exec
2376 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2377 curhdr->pair = color->pair;
2380 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];