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>
26 #include "recvattach.h"
31 #include <imap/imap_private.h>
33 #include <lib-crypt/crypt.h>
36 #include "nntp/nntp.h"
40 #include "mutt_sasl.h"
43 static const char *No_mailbox_is_open = N_("No mailbox is open.");
44 static const char *There_are_no_messages = N_("There are no messages.");
45 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
46 static const char *Function_not_permitted_in_attach_message_mode =
47 N_("Function not permitted in attach-message mode.");
48 static const char *No_visible = N_("No visible messages.");
50 #define CHECK_IN_MAILBOX if (!Context) \
53 mutt_error (_(No_mailbox_is_open)); \
57 #define CHECK_MSGCOUNT if (!Context) \
60 mutt_error(_(No_mailbox_is_open)); \
63 else if (!Context->msgcount) \
66 mutt_error(_(There_are_no_messages)); \
70 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
73 mutt_error(_(No_visible)); \
78 #define CHECK_READONLY if (Context->readonly) \
81 mutt_error(_(Mailbox_is_read_only)); \
85 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
88 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
92 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
93 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
94 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
95 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
97 extern size_t UngetCount;
99 void index_make_entry (char *s, ssize_t l, struct menu_t * menu, int num)
102 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
103 int edgemsgno, reverse = Sort & SORT_REVERSE;
104 HEADER *h = Context->hdrs[Context->v2r[num]];
107 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
108 flag |= M_FORMAT_TREE; /* display the thread tree */
109 if (h->display_subject)
110 flag |= M_FORMAT_FORCESUBJ;
113 if (menu->top + menu->pagelen > menu->max)
114 edgemsgno = Context->v2r[menu->max - 1];
116 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
119 edgemsgno = Context->v2r[menu->top];
121 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
125 /* if no ancestor is visible on current screen, provisionally force
127 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
129 flag |= M_FORMAT_FORCESUBJ;
132 else if (tmp->message->virtual >= 0)
135 if (flag & M_FORMAT_FORCESUBJ) {
136 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
140 /* ...but if a previous sibling is available, don't force it */
141 if (reverse ? tmp->message->msgno >
142 edgemsgno : tmp->message->msgno < edgemsgno)
144 else if (tmp->message->virtual >= 0) {
145 flag &= ~M_FORMAT_FORCESUBJ;
153 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
156 int index_color (int index_no)
158 HEADER *h = Context->hdrs[Context->v2r[index_no]];
163 mutt_set_header_color (Context, h);
167 static int ci_next_undeleted (int msgno)
171 for (i = msgno + 1; i < Context->vcount; i++)
172 if (!Context->hdrs[Context->v2r[i]]->deleted)
177 static int ci_previous_undeleted (int msgno)
181 for (i = msgno - 1; i >= 0; i--)
182 if (!Context->hdrs[Context->v2r[i]]->deleted)
187 /* Return the index of the first new message, or failing that, the first
190 static int ci_first_message (void)
194 if (Context && Context->msgcount) {
195 for (i = 0; i < Context->vcount; i++) {
196 if (!Context->hdrs[Context->v2r[i]]->read &&
197 !Context->hdrs[Context->v2r[i]]->deleted) {
198 if (!Context->hdrs[Context->v2r[i]]->old)
207 /* If Sort is reverse and not threaded, the latest message is first.
208 * If Sort is threaded, the latest message is first iff exactly one
209 * of Sort and SortAux are reverse.
211 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
212 ((Sort & SORT_MASK) == SORT_THREADS &&
213 ((Sort ^ SortAux) & SORT_REVERSE)))
216 return (Context->vcount ? Context->vcount - 1 : 0);
221 /* This should be in mx.c, but it only gets used here. */
222 static int mx_toggle_write (CONTEXT * ctx)
228 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
233 if (ctx->dontwrite) {
235 mutt_message (_("Changes to folder will be written on folder exit."));
239 mutt_message (_("Changes to folder will not be written."));
245 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
246 int oldcount, int index_hint)
248 /* store pointers to the newly added messages */
249 HEADER **save_new = NULL;
252 /* take note of the current message */
254 if (menu->current < Context->vcount)
255 menu->oldcurrent = index_hint;
257 oldcount = 0; /* invalid message number! */
260 /* We are in a limited view. Check if the new message(s) satisfy
261 * the limit criteria. If they do, set their virtual msgno so that
262 * they will be visible in the limited view */
263 if (Context->pattern) {
264 #define THIS_BODY Context->hdrs[j]->content
265 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
266 if (mutt_pattern_exec
267 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
269 Context->hdrs[j]->virtual = Context->vcount;
270 Context->v2r[Context->vcount] = j;
271 Context->hdrs[j]->limited = 1;
274 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
280 /* save the list of new messages */
281 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
282 save_new = p_new(HEADER*, Context->msgcount - oldcount);
283 for (j = oldcount; j < Context->msgcount; j++)
284 save_new[j - oldcount] = Context->hdrs[j];
287 /* if the mailbox was reopened, need to rethread from scratch */
288 mutt_sort_headers (Context, (check == M_REOPENED));
290 /* uncollapse threads with new mail */
291 if ((Sort & SORT_MASK) == SORT_THREADS) {
292 if (check == M_REOPENED) {
295 Context->collapsed = 0;
297 for (h = Context->tree; h; h = h->next) {
298 for (c = h; !c->message; c = c->child);
299 mutt_uncollapse_thread (Context, c->message);
301 mutt_set_virtual (Context);
304 for (j = 0; j < Context->msgcount - oldcount; j++) {
307 for (k = 0; k < Context->msgcount; k++) {
308 HEADER *h = Context->hdrs[k];
310 if (h == save_new[j] && (!Context->pattern || h->limited))
311 mutt_uncollapse_thread (Context, h);
315 mutt_set_virtual (Context);
321 /* restore the current message to the message it was pointing to */
322 for (j = 0; j < Context->vcount; j++) {
323 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
330 if (menu->current < 0)
331 menu->current = ci_first_message ();
334 static void resort_index (MUTTMENU * menu)
337 HEADER *current = CURHDR;
340 mutt_sort_headers (Context, 0);
341 /* Restore the current message */
343 for (i = 0; i < Context->vcount; i++) {
344 if (Context->hdrs[Context->v2r[i]] == current) {
350 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
351 menu->current = mutt_parent_message (Context, current);
353 if (menu->current < 0)
354 menu->current = ci_first_message ();
356 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
359 struct mapping_t IndexHelp[] = {
360 {N_("Quit"), OP_QUIT},
361 {N_("Del"), OP_DELETE},
362 {N_("Undel"), OP_UNDELETE},
363 {N_("Save"), OP_SAVE},
364 {N_("Mail"), OP_MAIL},
365 {N_("Reply"), OP_REPLY},
366 {N_("Group"), OP_GROUP_REPLY},
367 {N_("Help"), OP_HELP},
372 struct mapping_t IndexNewsHelp[] = {
373 {N_("Quit"), OP_QUIT},
374 {N_("Del"), OP_DELETE},
375 {N_("Undel"), OP_UNDELETE},
376 {N_("Save"), OP_SAVE},
377 {N_("Post"), OP_POST},
378 {N_("Followup"), OP_FOLLOWUP},
379 {N_("Catchup"), OP_CATCHUP},
380 {N_("Help"), OP_HELP},
385 /* This function handles the message index window as well as commands returned
386 * from the pager (MENU_PAGER).
388 int mutt_index_menu (void)
390 char buf[LONG_STRING], helpstr[SHORT_STRING];
393 int done = 0; /* controls when to exit the "event" loop */
395 int tag = 0; /* has the tag-prefix command been pressed? */
400 char *cp; /* temporary variable. */
401 int index_hint; /* used to restore cursor position */
402 int do_buffy_notify = 1;
403 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
404 int attach_msg = option (OPTATTACHMSG);
406 menu = mutt_new_menu ();
407 menu->menu = MENU_MAIN;
409 menu->pagelen = LINES - 3;
410 menu->make_entry = (void *) index_make_entry;
411 menu->color = index_color;
412 menu->current = ci_first_message ();
413 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
416 && (Context->magic ==
417 M_NNTP)) ? IndexNewsHelp :
422 buffy_check (0); /* force the buffy check after we enter the folder */
423 /* record folder we open to place sidebar indicator properly */
424 if (Context && Context->path)
425 sidebar_set_current (Context->path);
429 tag = 0; /* clear the tag-prefix */
431 menu->max = Context ? Context->vcount : 0;
432 oldcount = Context ? Context->msgcount : 0;
434 /* check if we need to resort the index because just about
435 * any 'op' below could do mutt_enter_command(), either here or
436 * from any new menu launched, and change $sort/$sort_aux
438 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
441 if (option (OPTREDRAWTREE) && Context && Context->msgcount
442 && (Sort & SORT_MASK) == SORT_THREADS) {
443 mutt_draw_tree (Context);
444 menu->redraw |= REDRAW_STATUS;
445 unset_option (OPTREDRAWTREE);
448 if (Context && !attach_msg) {
451 /* check for new mail in the mailbox. If nonzero, then something has
452 * changed about the file (either we got new mail or the file was
453 * modified underneath us.)
456 imap_allow_reopen (Context);
458 index_hint = (Context->vcount && menu->current >= 0
459 && menu->current < Context->vcount) ? CURHDR->index : 0;
461 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
462 if (!Context->path) {
463 /* fatal error occurred */
465 menu->redraw = REDRAW_FULL;
467 set_option (OPTSEARCHINVALID);
469 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
470 update_index (menu, Context, check, oldcount, index_hint);
472 /* notify the user of new mail */
473 if (check == M_REOPENED)
475 ("Mailbox was externally modified. Flags may be wrong."));
476 else if (check == M_NEW_MAIL) {
477 /* on new mail: redraw sidebar */
479 mutt_message (_("New mail in this mailbox."));
481 if (option (OPTBEEPNEW))
484 else if (check == M_FLAGS)
485 mutt_message (_("Mailbox was externally modified."));
487 /* avoid the message being overwritten by buffy */
490 menu->redraw = REDRAW_FULL;
491 menu->max = Context->vcount;
493 set_option (OPTSEARCHINVALID);
498 imap_disallow_reopen (Context);
501 /* check for new mail in the incoming folders */
503 if ((newcount = buffy_check (0)) != oldcount) {
504 menu->redraw |= REDRAW_STATUS;
505 menu->redraw |= REDRAW_SIDEBAR;
507 if (do_buffy_notify) {
508 if (buffy_notify () && option (OPTBEEPNEW))
517 if (menu->redraw & REDRAW_SIDEBAR)
519 if (menu->redraw & REDRAW_FULL) {
520 menu_redraw_full (menu);
525 if (menu->menu == MENU_MAIN) {
526 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
527 menu_check_recenter (menu);
529 if (menu->redraw & REDRAW_INDEX) {
530 menu_redraw_index (menu);
531 menu->redraw |= REDRAW_STATUS;
533 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
534 menu_redraw_motion (menu);
535 else if (menu->redraw & REDRAW_CURRENT)
536 menu_redraw_current (menu);
539 if (menu->redraw & REDRAW_STATUS) {
540 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
541 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
542 sidebar_draw_frames();
543 SETCOLOR (MT_COLOR_STATUS);
544 BKGDSET (MT_COLOR_STATUS);
545 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
546 mutt_paddstr (COLS-SW, buf);
547 SETCOLOR (MT_COLOR_NORMAL);
548 BKGDSET (MT_COLOR_NORMAL);
549 sidebar_set_buffystats (Context);
550 menu->redraw &= ~REDRAW_STATUS;
551 if (option (OPTXTERMSETTITLES)) {
552 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
553 mutt_xterm_set_title (buf);
554 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
555 mutt_xterm_set_icon (buf);
560 if (menu->current < menu->max)
561 menu->oldcurrent = menu->current;
563 menu->oldcurrent = -1;
565 if (option (OPTARROWCURSOR))
566 move (menu->current - menu->top + menu->offset, 2);
567 else if (option (OPTBRAILLEFRIENDLY))
568 move (menu->current - menu->top + menu->offset, 0);
570 move (menu->current - menu->top + menu->offset, COLS - 1);
573 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
576 mutt_resize_screen ();
577 menu->redraw = REDRAW_FULL;
578 menu->menu = MENU_MAIN;
580 menu->top = 0; /* so we scroll the right amount */
582 * force a real complete redraw. clrtobot() doesn't seem to be able
583 * to handle every case without this.
585 clearok (stdscr, TRUE);
590 op = km_dokey (MENU_MAIN);
593 continue; /* either user abort or timeout */
597 /* special handling for the tag-prefix function */
598 if (op == OP_TAG_PREFIX) {
600 mutt_error (_("No mailbox is open."));
605 if (!Context->tagged) {
606 mutt_error (_("No tagged messages."));
612 /* give visual indication that the next command is a tag- command */
613 mvaddstr (LINES - 1, 0, "tag-");
616 /* get the real command */
617 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
618 /* abort tag sequence */
619 CLEARLINE (LINES - 1);
623 else if (option (OPTAUTOTAG) && Context && Context->tagged)
626 if (op == OP_TAG_PREFIX_COND) {
628 mutt_error (_("No mailbox is open."));
633 if (!Context->tagged) {
636 while (UngetCount > 0) {
638 if (tmp.op == OP_END_COND)
641 mutt_message (_("Nothing to do."));
647 /* give visual indication that the next command is a tag- command */
648 mvaddstr (LINES - 1, 0, "tag-");
651 /* get the real command */
652 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
653 /* abort tag sequence */
654 CLEARLINE (LINES - 1);
662 if (menu->current < menu->max)
663 menu->oldcurrent = menu->current;
665 menu->oldcurrent = -1;
667 mutt_curs_set (1); /* fallback from the pager */
671 unset_option (OPTNEWS); /* for any case */
676 /* ----------------------------------------------------------------------
681 menu_bottom_page (menu);
684 menu_first_entry (menu);
687 menu_middle_page (menu);
693 menu_half_down (menu);
696 menu_next_line (menu);
699 menu_prev_line (menu);
702 menu_next_page (menu);
705 menu_prev_page (menu);
708 menu_last_entry (menu);
711 menu_top_page (menu);
714 menu_current_top (menu);
716 case OP_CURRENT_MIDDLE:
717 menu_current_middle (menu);
719 case OP_CURRENT_BOTTOM:
720 menu_current_bottom (menu);
727 if (Context->magic == M_NNTP) {
730 if (op == OP_GET_MESSAGE) {
732 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
737 string_list_t *ref = CURHDR->env->references;
740 mutt_error (_("Article has no parent reference!"));
744 m_strcpy(buf, sizeof(buf), ref->data);
746 if (!Context->id_hash)
747 Context->id_hash = mutt_make_id_hash (Context);
748 if ((h = hash_find (Context->id_hash, buf))) {
749 if (h->virtual != -1) {
750 menu->current = h->virtual;
751 menu->redraw = REDRAW_MOTION_RESYNCH;
753 else if (h->collapsed) {
754 mutt_uncollapse_thread (Context, h);
755 mutt_set_virtual (Context);
756 menu->current = h->virtual;
757 menu->redraw = REDRAW_MOTION_RESYNCH;
760 mutt_error (_("Message not visible in limited view."));
763 if (nntp_check_msgid (Context, buf) == 0) {
764 h = Context->hdrs[Context->msgcount - 1];
765 mutt_sort_headers (Context, 0);
766 menu->current = h->virtual;
767 menu->redraw = REDRAW_FULL;
770 mutt_error (_("Article %s not found on server"), buf);
775 case OP_GET_CHILDREN:
776 case OP_RECONSTRUCT_THREAD:
778 if (Context->magic == M_NNTP) {
780 int old = CURHDR->index;
782 if (!CURHDR->env->message_id) {
783 mutt_error (_("No Message-ID. Unable to perform operation"));
788 if (!Context->id_hash)
789 Context->id_hash = mutt_make_id_hash (Context);
790 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
792 if (op == OP_RECONSTRUCT_THREAD) {
793 string_list_t *ref = CURHDR->env->references;
796 nntp_check_msgid (Context, ref->data);
797 /* the last msgid in References is the root message */
799 m_strcpy(buf, sizeof(buf), ref->data);
803 mutt_message (_("Check for children of message..."));
805 if (nntp_check_children (Context, buf) == 0) {
806 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
807 h = hash_find (Context->id_hash, buf);
808 /* if the root message was retrieved, move to it */
810 menu->current = h->virtual;
811 else /* try to restore old position */
812 for (i = 0; i < Context->msgcount; i++)
813 if (Context->hdrs[i]->index == old) {
814 menu->current = Context->hdrs[i]->virtual;
815 /* As an added courtesy, recenter the menu
816 * with the current entry at the middle of the screen */
817 menu_check_recenter (menu);
818 menu_current_middle (menu);
821 menu->redraw = REDRAW_FULL;
831 if (isdigit (LastKey))
832 mutt_ungetch (LastKey, 0);
834 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
838 if (!isdigit ((unsigned char) buf[0])) {
839 mutt_error (_("Argument must be a message number."));
845 if (i > 0 && i <= Context->msgcount) {
846 for (j = i - 1; j < Context->msgcount; j++) {
847 if (Context->hdrs[j]->virtual != -1)
850 if (j >= Context->msgcount) {
851 for (j = i - 2; j >= 0; j--) {
852 if (Context->hdrs[j]->virtual != -1)
858 menu->current = Context->hdrs[j]->virtual;
859 if (menu->menu == MENU_PAGER) {
860 op = OP_DISPLAY_MESSAGE;
864 menu->redraw = REDRAW_MOTION;
867 mutt_error (_("That message is not visible."));
870 mutt_error (_("Invalid message number."));
874 /* --------------------------------------------------------------------
875 * `index' specific commands
878 case OP_MAIN_DELETE_PATTERN:
884 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
887 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
888 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
891 case OP_MAIN_FETCH_MAIL:
895 menu->redraw = REDRAW_FULL;
900 mutt_help (MENU_MAIN);
901 menu->redraw = REDRAW_FULL;
904 case OP_MAIN_SHOW_LIMIT:
906 if (!Context->pattern)
907 mutt_message (_("No limit pattern is in effect."));
912 /* i18n: ask for a limit to apply */
913 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
914 mutt_message ("%s", buffer);
922 menu->oldcurrent = (Context->vcount && menu->current >= 0
924 Context->vcount) ? CURHDR->index : -1;
925 if (op == OP_TOGGLE_READ) {
926 char buffer[LONG_STRING];
928 if (!Context->pattern
929 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
930 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
931 Context->pattern ? Context->pattern : ".*");
932 set_option (OPTHIDEREAD);
935 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
936 if (!*buf || strncmp (buf, ".*", 2) == 0)
937 snprintf (buf, sizeof (buf), "~A");
938 unset_option (OPTHIDEREAD);
940 p_delete(&Context->pattern);
941 Context->pattern = m_strdup(buf);
943 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
944 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
946 if (menu->oldcurrent >= 0) {
947 /* try to find what used to be the current message */
949 for (i = 0; i < Context->vcount; i++)
950 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
954 if (menu->current < 0)
959 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
960 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
961 mutt_draw_tree (Context);
962 menu->redraw = REDRAW_FULL;
964 if (Context->pattern)
965 mutt_message _("To view all messages, limit to \"all\".");
976 if (query_quadoption (OPT_QUIT, _("Quit Madmutt?")) == M_YES) {
979 oldcount = Context ? Context->msgcount : 0;
982 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
985 if (check == M_NEW_MAIL || check == M_REOPENED)
986 update_index (menu, Context, check, oldcount, index_hint);
988 menu->redraw = REDRAW_FULL; /* new mail arrived? */
989 set_option (OPTSEARCHINVALID);
996 clearok (stdscr, TRUE);
997 menu->redraw = REDRAW_FULL;
1001 case OP_SEARCH_REVERSE:
1002 case OP_SEARCH_NEXT:
1003 case OP_SEARCH_OPPOSITE:
1007 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1008 menu->current = menu->oldcurrent;
1010 menu->redraw = REDRAW_MOTION;
1014 case OP_SORT_REVERSE:
1016 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1017 if (Context && Context->msgcount) {
1018 resort_index (menu);
1019 set_option (OPTSEARCHINVALID);
1028 if (tag && !option (OPTAUTOTAG)) {
1029 for (j = 0; j < Context->vcount; j++)
1030 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1031 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1034 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1035 Context->last_tag = CURHDR->tagged ? CURHDR :
1036 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1037 ? NULL : Context->last_tag);
1038 menu->redraw = REDRAW_STATUS;
1039 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1041 menu->redraw |= REDRAW_MOTION_RESYNCH;
1044 menu->redraw |= REDRAW_CURRENT;
1048 case OP_MAIN_TAG_PATTERN:
1052 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1053 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1056 case OP_MAIN_UNDELETE_PATTERN:
1062 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1064 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1066 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1069 case OP_MAIN_UNTAG_PATTERN:
1073 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1074 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1077 /* --------------------------------------------------------------------
1078 * The following operations can be performed inside of the pager.
1081 case OP_MAIN_IMAP_FETCH:
1082 if (Context->magic == M_IMAP)
1083 imap_check_mailbox (Context, &index_hint, 1);
1086 case OP_MAIN_SYNC_FOLDER:
1088 if (Context && !Context->msgcount)
1095 int oldvcount = Context->vcount;
1096 oldcount = Context->msgcount;
1100 /* calculate the number of messages _above_ the cursor,
1101 * so we can keep the cursor on the current message
1103 for (j = 0; j <= menu->current; j++) {
1104 if (Context->hdrs[Context->v2r[j]]->deleted)
1108 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1109 if (Context->vcount != oldvcount)
1110 menu->current -= dcount;
1111 set_option (OPTSEARCHINVALID);
1113 else if (check == M_NEW_MAIL || check == M_REOPENED)
1114 update_index (menu, Context, check, oldcount, index_hint);
1117 * do a sanity check even if mx_sync_mailbox failed.
1120 if (menu->current < 0 || menu->current >= Context->vcount)
1121 menu->current = ci_first_message ();
1124 /* check for a fatal error, or all messages deleted */
1128 /* if we were in the pager, redisplay the message */
1129 if (menu->menu == MENU_PAGER) {
1130 op = OP_DISPLAY_MESSAGE;
1134 menu->redraw = REDRAW_FULL;
1137 case OP_SIDEBAR_OPEN:
1138 case OP_MAIN_CHANGE_FOLDER:
1139 case OP_MAIN_CHANGE_FOLDER_READONLY:
1141 case OP_MAIN_CHANGE_GROUP:
1142 case OP_MAIN_CHANGE_GROUP_READONLY:
1144 if (attach_msg || option (OPTREADONLY) ||
1146 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1148 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1154 cp = _("Open mailbox in read-only mode");
1156 cp = _("Open mailbox");
1160 unset_option (OPTNEWS);
1161 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1162 set_option (OPTNEWS);
1163 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1166 cp = _("Open newsgroup in read-only mode");
1168 cp = _("Open newsgroup");
1169 nntp_buffy (buf, sizeof (buf));
1174 if (Context && Context->path)
1175 m_strcpy(buf, sizeof(buf), Context->path);
1176 if (op != OP_SIDEBAR_OPEN)
1177 buffy_next (buf, sizeof (buf));
1180 if (op == OP_SIDEBAR_OPEN) {
1181 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1183 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1184 if (menu->menu == MENU_PAGER) {
1185 op = OP_DISPLAY_MESSAGE;
1191 CLEARLINE (LINES - 1);
1196 if (option (OPTNEWS)) {
1197 unset_option (OPTNEWS);
1198 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1202 mutt_expand_path (buf, sizeof (buf));
1203 if (mx_get_magic (buf) <= 0) {
1204 mutt_error (_("%s is not a mailbox."), buf);
1207 m_strreplace(&CurrentFolder, buf);
1212 if (Context->cinfo && Context->realpath)
1213 m_strreplace(&LastFolder, Context->realpath);
1215 m_strreplace(&LastFolder, Context->path);
1216 oldcount = Context ? Context->msgcount : 0;
1218 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1219 if (check == M_NEW_MAIL || check == M_REOPENED)
1220 update_index (menu, Context, check, oldcount, index_hint);
1222 set_option (OPTSEARCHINVALID);
1223 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1231 /* Set CurrentMenu to MENU_MAIN before executing any folder
1232 * hooks so that all the index menu functions are available to
1236 CurrentMenu = MENU_MAIN;
1237 mutt_folder_hook (buf);
1239 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1240 menu->current = ci_first_message ();
1244 sidebar_set_current (buf);
1247 /* buffy_check() must be done with mail-reader mode! */
1248 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1250 && (Context->magic ==
1251 M_NNTP)) ? IndexNewsHelp :
1254 mutt_clear_error ();
1255 buffy_check (0); /* force the buffy check after we have changed
1257 menu->redraw = REDRAW_FULL;
1258 set_option (OPTSEARCHINVALID);
1261 case OP_DISPLAY_MESSAGE:
1262 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1267 * toggle the weeding of headers so that a user can press the key
1268 * again while reading the message.
1270 if (op == OP_DISPLAY_HEADERS)
1271 toggle_option (OPTWEED);
1273 unset_option (OPTNEEDRESORT);
1275 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1276 mutt_uncollapse_thread (Context, CURHDR);
1277 mutt_set_virtual (Context);
1278 if (option (OPTUNCOLLAPSEJUMP))
1279 menu->current = mutt_thread_next_unread (Context, CURHDR);
1282 if (option (OPTPGPAUTODEC) &&
1283 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1284 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1286 if ((op = mutt_display_message (CURHDR)) == -1) {
1287 unset_option (OPTNEEDRESORT);
1291 menu->menu = MENU_PAGER;
1292 menu->oldcurrent = menu->current;
1298 if (menu->menu == MENU_MAIN && attach_msg) {
1303 if ((menu->menu == MENU_MAIN)
1304 && (query_quadoption (OPT_QUIT,
1305 _("Exit Madmutt without saving?")) == M_YES))
1308 mx_fastclose_mailbox (Context);
1320 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1321 /* if we were in the pager, redisplay the message */
1322 if (menu->menu == MENU_PAGER) {
1323 op = OP_DISPLAY_MESSAGE;
1327 menu->redraw = REDRAW_CURRENT;
1330 case OP_MAIN_BREAK_THREAD:
1336 if ((Sort & SORT_MASK) != SORT_THREADS)
1337 mutt_error (_("Threading is not enabled."));
1341 HEADER *oldcur = CURHDR;
1343 mutt_break_thread (CURHDR);
1344 mutt_sort_headers (Context, 1);
1345 menu->current = oldcur->virtual;
1348 Context->changed = 1;
1349 mutt_message _("Thread broken");
1351 if (menu->menu == MENU_PAGER) {
1352 op = OP_DISPLAY_MESSAGE;
1356 menu->redraw |= REDRAW_INDEX;
1360 case OP_MAIN_LINK_THREADS:
1366 if ((Sort & SORT_MASK) != SORT_THREADS)
1367 mutt_error (_("Threading is not enabled."));
1369 else if (!CURHDR->env->message_id)
1370 mutt_error (_("No Message-ID: header available to link thread"));
1372 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1373 mutt_error (_("First, please tag a message to be linked here"));
1376 HEADER *oldcur = CURHDR;
1378 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1380 mutt_sort_headers (Context, 1);
1381 menu->current = oldcur->virtual;
1383 Context->changed = 1;
1384 mutt_message _("Threads linked");
1387 mutt_error (_("No thread linked"));
1390 if (menu->menu == MENU_PAGER) {
1391 op = OP_DISPLAY_MESSAGE;
1395 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1398 case OP_MAIN_NEXT_UNDELETED:
1402 if (menu->current >= Context->vcount - 1) {
1403 if (menu->menu == MENU_MAIN)
1404 mutt_error (_("You are on the last message."));
1408 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1409 menu->current = menu->oldcurrent;
1410 if (menu->menu == MENU_MAIN)
1411 mutt_error (_("No undeleted messages."));
1413 else if (menu->menu == MENU_PAGER) {
1414 op = OP_DISPLAY_MESSAGE;
1418 menu->redraw = REDRAW_MOTION;
1425 if (menu->current >= Context->vcount - 1) {
1426 if (menu->menu == MENU_MAIN)
1427 mutt_error (_("You are on the last message."));
1432 if (menu->menu == MENU_PAGER) {
1433 op = OP_DISPLAY_MESSAGE;
1437 menu->redraw = REDRAW_MOTION;
1440 case OP_MAIN_PREV_UNDELETED:
1444 if (menu->current < 1) {
1445 mutt_error (_("You are on the first message."));
1449 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1450 menu->current = menu->oldcurrent;
1451 if (menu->menu == MENU_MAIN)
1452 mutt_error (_("No undeleted messages."));
1454 else if (menu->menu == MENU_PAGER) {
1455 op = OP_DISPLAY_MESSAGE;
1459 menu->redraw = REDRAW_MOTION;
1466 if (menu->current < 1) {
1467 if (menu->menu == MENU_MAIN)
1468 mutt_error (_("You are on the first message."));
1473 if (menu->menu == MENU_PAGER) {
1474 op = OP_DISPLAY_MESSAGE;
1478 menu->redraw = REDRAW_MOTION;
1481 case OP_DECRYPT_COPY:
1482 case OP_DECRYPT_SAVE:
1483 case OP_COPY_MESSAGE:
1485 case OP_DECODE_COPY:
1486 case OP_DECODE_SAVE:
1489 if (mutt_save_message (tag ? NULL : CURHDR,
1490 (op == OP_DECRYPT_SAVE) ||
1491 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1492 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1493 (op == OP_DECRYPT_SAVE)
1494 || (op == OP_DECRYPT_COPY)
1495 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1502 menu->redraw |= REDRAW_INDEX;
1503 else if (option (OPTRESOLVE)) {
1504 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1505 menu->current = menu->oldcurrent;
1506 menu->redraw |= REDRAW_CURRENT;
1509 menu->redraw |= REDRAW_MOTION_RESYNCH;
1512 menu->redraw |= REDRAW_CURRENT;
1516 case OP_MAIN_NEXT_NEW:
1517 case OP_MAIN_NEXT_UNREAD:
1518 case OP_MAIN_PREV_NEW:
1519 case OP_MAIN_PREV_UNREAD:
1520 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1521 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1524 int first_unread = -1;
1532 for (j = 0; j != Context->vcount; j++) {
1533 #define CURHDRi Context->hdrs[Context->v2r[i]]
1534 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1535 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1537 if (i > Context->vcount - 1) {
1538 mutt_message _("Search wrapped to top.");
1546 mutt_message _("Search wrapped to bottom.");
1548 i = Context->vcount - 1;
1552 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1553 if (UNREAD (CURHDRi) && first_unread == -1)
1555 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1558 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1559 if (first_unread == -1)
1561 if ((!CURHDRi->old) && first_new == -1)
1565 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1568 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1569 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1570 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1575 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1576 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1577 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1579 menu->current = first_new;
1580 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1581 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1582 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1583 && first_unread != -1)
1584 menu->current = first_unread;
1586 if (menu->current == -1) {
1587 menu->current = menu->oldcurrent;
1588 mutt_error ("%s%s.",
1589 (op == OP_MAIN_NEXT_NEW
1591 OP_MAIN_PREV_NEW) ? _("No new messages") :
1592 _("No unread messages"),
1593 Context->pattern ? _(" in this limited view") : "");
1595 else if (menu->menu == MENU_PAGER) {
1596 op = OP_DISPLAY_MESSAGE;
1600 menu->redraw = REDRAW_MOTION;
1603 case OP_FLAG_MESSAGE:
1609 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1612 for (j = 0; j < Context->vcount; j++) {
1613 if (Context->hdrs[Context->v2r[j]]->tagged)
1614 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1615 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1618 menu->redraw |= REDRAW_INDEX;
1621 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1622 if (option (OPTRESOLVE)) {
1623 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1624 menu->current = menu->oldcurrent;
1625 menu->redraw = REDRAW_CURRENT;
1628 menu->redraw = REDRAW_MOTION_RESYNCH;
1631 menu->redraw = REDRAW_CURRENT;
1633 menu->redraw |= REDRAW_STATUS;
1642 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1645 for (j = 0; j < Context->vcount; j++) {
1646 if (Context->hdrs[Context->v2r[j]]->tagged) {
1647 if (Context->hdrs[Context->v2r[j]]->read ||
1648 Context->hdrs[Context->v2r[j]]->old)
1649 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1652 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1656 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1659 if (CURHDR->read || CURHDR->old)
1660 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1662 mutt_set_flag (Context, CURHDR, M_READ, 1);
1664 if (option (OPTRESOLVE)) {
1665 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1666 menu->current = menu->oldcurrent;
1667 menu->redraw = REDRAW_CURRENT;
1670 menu->redraw = REDRAW_MOTION_RESYNCH;
1673 menu->redraw = REDRAW_CURRENT;
1674 menu->redraw |= REDRAW_STATUS;
1678 case OP_TOGGLE_WRITE:
1681 if (mx_toggle_write (Context) == 0)
1682 menu->redraw |= REDRAW_STATUS;
1685 case OP_MAIN_NEXT_THREAD:
1686 case OP_MAIN_NEXT_SUBTHREAD:
1687 case OP_MAIN_PREV_THREAD:
1688 case OP_MAIN_PREV_SUBTHREAD:
1693 case OP_MAIN_NEXT_THREAD:
1694 menu->current = mutt_next_thread (CURHDR);
1697 case OP_MAIN_NEXT_SUBTHREAD:
1698 menu->current = mutt_next_subthread (CURHDR);
1701 case OP_MAIN_PREV_THREAD:
1702 menu->current = mutt_previous_thread (CURHDR);
1705 case OP_MAIN_PREV_SUBTHREAD:
1706 menu->current = mutt_previous_subthread (CURHDR);
1710 if (menu->current < 0) {
1711 menu->current = menu->oldcurrent;
1712 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1713 mutt_error (_("No more threads."));
1716 mutt_error (_("You are on the first thread."));
1718 else if (menu->menu == MENU_PAGER) {
1719 op = OP_DISPLAY_MESSAGE;
1723 menu->redraw = REDRAW_MOTION;
1726 case OP_MAIN_PARENT_MESSAGE:
1731 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1732 menu->current = menu->oldcurrent;
1734 else if (menu->menu == MENU_PAGER) {
1735 op = OP_DISPLAY_MESSAGE;
1739 menu->redraw = REDRAW_MOTION;
1742 case OP_MAIN_SET_FLAG:
1743 case OP_MAIN_CLEAR_FLAG:
1749 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1751 menu->redraw = REDRAW_STATUS;
1753 menu->redraw |= REDRAW_INDEX;
1754 else if (option (OPTRESOLVE)) {
1755 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1756 menu->current = menu->oldcurrent;
1757 menu->redraw |= REDRAW_CURRENT;
1760 menu->redraw |= REDRAW_MOTION_RESYNCH;
1763 menu->redraw |= REDRAW_CURRENT;
1767 case OP_MAIN_COLLAPSE_THREAD:
1771 if ((Sort & SORT_MASK) != SORT_THREADS) {
1772 mutt_error (_("Threading is not enabled."));
1777 if (CURHDR->collapsed) {
1778 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1779 mutt_set_virtual (Context);
1780 if (option (OPTUNCOLLAPSEJUMP))
1781 menu->current = mutt_thread_next_unread (Context, CURHDR);
1783 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1784 menu->current = mutt_collapse_thread (Context, CURHDR);
1785 mutt_set_virtual (Context);
1788 mutt_error (_("Thread contains unread messages."));
1793 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1797 case OP_MAIN_COLLAPSE_ALL:
1801 if ((Sort & SORT_MASK) != SORT_THREADS) {
1802 mutt_error (_("Threading is not enabled."));
1809 THREAD *thread, *top;
1812 if (CURHDR->collapsed)
1813 final = mutt_uncollapse_thread (Context, CURHDR);
1814 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1815 final = mutt_collapse_thread (Context, CURHDR);
1817 final = CURHDR->virtual;
1819 base = Context->hdrs[Context->v2r[final]];
1821 top = Context->tree;
1822 Context->collapsed = !Context->collapsed;
1823 while ((thread = top) != NULL) {
1824 while (!thread->message)
1825 thread = thread->child;
1826 h = thread->message;
1828 if (h->collapsed != Context->collapsed) {
1830 mutt_uncollapse_thread (Context, h);
1831 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1832 mutt_collapse_thread (Context, h);
1837 mutt_set_virtual (Context);
1838 for (j = 0; j < Context->vcount; j++) {
1839 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1845 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1849 /* --------------------------------------------------------------------
1850 * These functions are invoked directly from the internal-pager
1853 case OP_BOUNCE_MESSAGE:
1858 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1861 case OP_CREATE_ALIAS:
1863 mutt_create_alias (Context
1864 && Context->vcount ? CURHDR->env : NULL, NULL);
1865 MAYBE_REDRAW (menu->redraw);
1866 menu->redraw |= REDRAW_CURRENT;
1871 mutt_query_menu (NULL, 0);
1872 MAYBE_REDRAW (menu->redraw);
1875 case OP_PURGE_MESSAGE:
1882 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1885 mutt_tag_set_flag (M_DELETE, 1);
1886 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1887 if (option (OPTDELETEUNTAG))
1888 mutt_tag_set_flag (M_TAG, 0);
1889 menu->redraw = REDRAW_INDEX;
1892 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1893 mutt_set_flag (Context, CURHDR, M_PURGED,
1894 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1895 if (option (OPTDELETEUNTAG))
1896 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1897 if (option (OPTRESOLVE)) {
1898 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1899 menu->current = menu->oldcurrent;
1900 menu->redraw = REDRAW_CURRENT;
1902 else if (menu->menu == MENU_PAGER) {
1903 op = OP_DISPLAY_MESSAGE;
1907 menu->redraw |= REDRAW_MOTION_RESYNCH;
1910 menu->redraw = REDRAW_CURRENT;
1912 menu->redraw |= REDRAW_STATUS;
1915 case OP_DELETE_THREAD:
1916 case OP_DELETE_SUBTHREAD:
1922 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1924 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1925 op == OP_DELETE_THREAD ? 0 : 1);
1928 if (option (OPTDELETEUNTAG))
1929 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1930 op == OP_DELETE_THREAD ? 0 : 1);
1931 if (option (OPTRESOLVE))
1932 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1933 menu->current = menu->oldcurrent;
1934 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1940 if (Context && Context->magic == M_NNTP) {
1941 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1942 ((NNTP_DATA *) Context->data)->group))
1943 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1948 case OP_DISPLAY_ADDRESS:
1952 mutt_display_address (CURHDR->env);
1955 case OP_ENTER_COMMAND:
1957 CurrentMenu = MENU_MAIN;
1958 mutt_enter_command ();
1959 mutt_check_rescore (Context);
1960 if (option (OPTFORCEREDRAWINDEX))
1961 menu->redraw = REDRAW_FULL;
1962 unset_option (OPTFORCEREDRAWINDEX);
1963 unset_option (OPTFORCEREDRAWPAGER);
1966 case OP_EDIT_MESSAGE:
1973 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1975 if (option (OPTPGPAUTODEC)
1976 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1977 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1978 mutt_edit_message (Context, tag ? NULL : CURHDR);
1979 menu->redraw = REDRAW_FULL;
1983 case OP_FORWARD_MESSAGE:
1989 if (option (OPTPGPAUTODEC) &&
1990 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1991 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1992 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
1993 menu->redraw = REDRAW_FULL;
1997 case OP_FORGET_PASSPHRASE:
1998 crypt_forget_passphrase ();
2001 case OP_GROUP_REPLY:
2007 if (option (OPTPGPAUTODEC) &&
2008 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2009 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2011 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2012 tag ? NULL : CURHDR);
2013 menu->redraw = REDRAW_FULL;
2022 if (option (OPTPGPAUTODEC) &&
2023 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2024 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2026 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2027 tag ? NULL : CURHDR);
2028 menu->redraw = REDRAW_FULL;
2034 ci_send_message (0, NULL, NULL, Context, NULL);
2035 menu->redraw = REDRAW_FULL;
2040 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2041 menu->redraw = REDRAW_FULL;
2045 case OP_EXTRACT_KEYS:
2048 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2049 menu->redraw = REDRAW_FULL;
2053 case OP_CHECK_TRADITIONAL:
2056 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2057 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2059 if (menu->menu == MENU_PAGER) {
2060 op = OP_DISPLAY_MESSAGE;
2069 mutt_pipe_message (tag ? NULL : CURHDR);
2070 /* in an IMAP folder index with imap_peek=no, piping could change
2071 * * new or old messages status to read. Redraw what's needed.
2073 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2074 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2076 MAYBE_REDRAW (menu->redraw);
2083 mutt_print_message (tag ? NULL : CURHDR);
2084 /* in an IMAP folder index with imap_peek=no, piping could change
2085 * * new or old messages status to read. Redraw what's needed.
2087 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2088 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2092 case OP_MAIN_READ_THREAD:
2093 case OP_MAIN_READ_SUBTHREAD:
2099 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2101 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2102 op == OP_MAIN_READ_THREAD ? 0 : 1);
2105 if (option (OPTRESOLVE)) {
2106 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2107 mutt_next_thread (CURHDR) :
2108 mutt_next_subthread (CURHDR))) == -1)
2109 menu->current = menu->oldcurrent;
2111 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2115 case OP_RECALL_MESSAGE:
2118 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2119 menu->redraw = REDRAW_FULL;
2129 for (j = 0; j < Context->vcount; j++) {
2130 if (Context->hdrs[Context->v2r[j]]->tagged)
2131 mutt_resend_message (NULL, Context,
2132 Context->hdrs[Context->v2r[j]]);
2136 mutt_resend_message (NULL, Context, CURHDR);
2138 menu->redraw = REDRAW_FULL;
2144 case OP_FORWARD_TO_GROUP:
2147 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2148 Context && Context->msgcount == 0) {
2149 mutt_error (_("There are no messages."));
2152 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2153 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2154 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2155 _("Reply by mail as poster prefers?")) !=
2157 if (Context && Context->magic == M_NNTP
2158 && !((NNTP_DATA *) Context->data)->allowed
2159 && query_quadoption (OPT_TOMODERATED,
2161 ("Posting to this group not allowed, may be moderated. Continue?"))
2165 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2168 if (op == OP_FOLLOWUP)
2169 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2170 tag ? NULL : CURHDR);
2172 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2173 tag ? NULL : CURHDR);
2175 menu->redraw = REDRAW_FULL;
2186 if (option (OPTPGPAUTODEC) &&
2187 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2188 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2190 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2191 menu->redraw = REDRAW_FULL;
2194 case OP_SHELL_ESCAPE:
2196 mutt_shell_escape ();
2197 MAYBE_REDRAW (menu->redraw);
2201 case OP_TAG_SUBTHREAD:
2205 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2206 op == OP_TAG_THREAD ? 0 : 1);
2209 if (option (OPTRESOLVE)) {
2210 menu->current = mutt_next_thread (CURHDR);
2212 if (menu->current == -1)
2213 menu->current = menu->oldcurrent;
2215 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2225 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2228 mutt_tag_set_flag (M_DELETE, 0);
2229 mutt_tag_set_flag (M_PURGED, 0);
2230 menu->redraw = REDRAW_INDEX;
2233 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2234 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2235 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2237 menu->redraw = REDRAW_MOTION_RESYNCH;
2240 menu->redraw = REDRAW_CURRENT;
2242 menu->redraw |= REDRAW_STATUS;
2245 case OP_UNDELETE_THREAD:
2246 case OP_UNDELETE_SUBTHREAD:
2252 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2254 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2255 op == OP_UNDELETE_THREAD ? 0 : 1)
2256 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2257 op == OP_UNDELETE_THREAD ? 0 : 1);
2260 if (option (OPTRESOLVE)) {
2261 if (op == OP_UNDELETE_THREAD)
2262 menu->current = mutt_next_thread (CURHDR);
2264 menu->current = mutt_next_subthread (CURHDR);
2266 if (menu->current == -1)
2267 menu->current = menu->oldcurrent;
2269 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2278 if (option (OPTFORCEBUFFYCHECK))
2281 menu->redraw = REDRAW_FULL;
2284 case OP_VIEW_ATTACHMENTS:
2287 mutt_view_attachments (CURHDR);
2288 if (CURHDR->attach_del)
2289 Context->changed = 1;
2290 menu->redraw = REDRAW_FULL;
2300 case OP_REBUILD_CACHE:
2301 mx_rebuild_cache ();
2304 case OP_SIDEBAR_SCROLL_UP:
2305 case OP_SIDEBAR_SCROLL_DOWN:
2306 case OP_SIDEBAR_NEXT:
2307 case OP_SIDEBAR_PREV:
2308 case OP_SIDEBAR_NEXT_NEW:
2309 case OP_SIDEBAR_PREV_NEW:
2310 sidebar_scroll (op);
2313 if (menu->menu == MENU_MAIN)
2314 km_error_key (MENU_MAIN);
2317 if (menu->menu == MENU_PAGER) {
2318 menu->menu = MENU_MAIN;
2319 menu->redraw = REDRAW_FULL;
2321 set_option (OPTWEED); /* turn header weeding back on. */
2330 /* Close all open IMAP connections */
2333 /* Close all open NNTP connections */
2341 mutt_menuDestroy (&menu);
2345 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2352 for (color = ColorIndexList; color; color = color->next)
2353 if (mutt_pattern_exec
2354 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2355 curhdr->pair = color->pair;
2358 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];