2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * Parts were written/modified by:
6 * Nico Golde <nico@ngolde.de>
8 * This file is part of mutt-ng, see http://www.muttng.org/.
9 * It's licensed under the GNU General Public License,
10 * please see the file GPL in the top level source directory.
13 #include <lib-lib/lib-lib.h>
15 #include <lib-ui/sidebar.h>
16 #include <lib-mx/mx.h>
17 #include <lib-crypt/crypt.h>
28 #include "recvattach.h"
32 #include <imap/imap_private.h>
35 #include <nntp/nntp.h>
39 #include "mutt_sasl.h"
42 static const char *No_mailbox_is_open = N_("No mailbox is open.");
43 static const char *There_are_no_messages = N_("There are no messages.");
44 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
45 static const char *Function_not_permitted_in_attach_message_mode =
46 N_("Function not permitted in attach-message mode.");
47 static const char *No_visible = N_("No visible messages.");
49 #define CHECK_IN_MAILBOX if (!Context) \
52 mutt_error (_(No_mailbox_is_open)); \
56 #define CHECK_MSGCOUNT if (!Context) \
59 mutt_error(_(No_mailbox_is_open)); \
62 else if (!Context->msgcount) \
65 mutt_error(_(There_are_no_messages)); \
69 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
72 mutt_error(_(No_visible)); \
77 #define CHECK_READONLY if (Context->readonly) \
80 mutt_error(_(Mailbox_is_read_only)); \
84 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
87 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
91 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
92 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
93 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
94 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
96 extern size_t UngetCount;
98 void index_make_entry (char *s, ssize_t l, struct menu_t * menu, int num)
101 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
102 int edgemsgno, reverse = Sort & SORT_REVERSE;
103 HEADER *h = Context->hdrs[Context->v2r[num]];
106 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
107 flag |= M_FORMAT_TREE; /* display the thread tree */
108 if (h->display_subject)
109 flag |= M_FORMAT_FORCESUBJ;
112 if (menu->top + menu->pagelen > menu->max)
113 edgemsgno = Context->v2r[menu->max - 1];
115 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
118 edgemsgno = Context->v2r[menu->top];
120 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
124 /* if no ancestor is visible on current screen, provisionally force
126 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
128 flag |= M_FORMAT_FORCESUBJ;
131 else if (tmp->message->virtual >= 0)
134 if (flag & M_FORMAT_FORCESUBJ) {
135 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
139 /* ...but if a previous sibling is available, don't force it */
140 if (reverse ? tmp->message->msgno >
141 edgemsgno : tmp->message->msgno < edgemsgno)
143 else if (tmp->message->virtual >= 0) {
144 flag &= ~M_FORMAT_FORCESUBJ;
152 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
155 int index_color (int index_no)
157 HEADER *h = Context->hdrs[Context->v2r[index_no]];
162 mutt_set_header_color (Context, h);
166 static int ci_next_undeleted (int msgno)
170 for (i = msgno + 1; i < Context->vcount; i++)
171 if (!Context->hdrs[Context->v2r[i]]->deleted)
176 static int ci_previous_undeleted (int msgno)
180 for (i = msgno - 1; i >= 0; i--)
181 if (!Context->hdrs[Context->v2r[i]]->deleted)
186 /* Return the index of the first new message, or failing that, the first
189 static int ci_first_message (void)
193 if (Context && Context->msgcount) {
194 for (i = 0; i < Context->vcount; i++) {
195 if (!Context->hdrs[Context->v2r[i]]->read &&
196 !Context->hdrs[Context->v2r[i]]->deleted) {
197 if (!Context->hdrs[Context->v2r[i]]->old)
206 /* If Sort is reverse and not threaded, the latest message is first.
207 * If Sort is threaded, the latest message is first iff exactly one
208 * of Sort and SortAux are reverse.
210 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
211 ((Sort & SORT_MASK) == SORT_THREADS &&
212 ((Sort ^ SortAux) & SORT_REVERSE)))
215 return (Context->vcount ? Context->vcount - 1 : 0);
220 /* This should be in mx.c, but it only gets used here. */
221 static int mx_toggle_write (CONTEXT * ctx)
227 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
232 if (ctx->dontwrite) {
234 mutt_message (_("Changes to folder will be written on folder exit."));
238 mutt_message (_("Changes to folder will not be written."));
244 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
245 int oldcount, int index_hint)
247 /* store pointers to the newly added messages */
248 HEADER **save_new = NULL;
251 /* take note of the current message */
253 if (menu->current < Context->vcount)
254 menu->oldcurrent = index_hint;
256 oldcount = 0; /* invalid message number! */
259 /* We are in a limited view. Check if the new message(s) satisfy
260 * the limit criteria. If they do, set their virtual msgno so that
261 * they will be visible in the limited view */
262 if (Context->pattern) {
263 #define THIS_BODY Context->hdrs[j]->content
264 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
265 if (mutt_pattern_exec
266 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
268 Context->hdrs[j]->virtual = Context->vcount;
269 Context->v2r[Context->vcount] = j;
270 Context->hdrs[j]->limited = 1;
273 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
279 /* save the list of new messages */
280 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
281 save_new = p_new(HEADER*, Context->msgcount - oldcount);
282 for (j = oldcount; j < Context->msgcount; j++)
283 save_new[j - oldcount] = Context->hdrs[j];
286 /* if the mailbox was reopened, need to rethread from scratch */
287 mutt_sort_headers (Context, (check == M_REOPENED));
289 /* uncollapse threads with new mail */
290 if ((Sort & SORT_MASK) == SORT_THREADS) {
291 if (check == M_REOPENED) {
294 Context->collapsed = 0;
296 for (h = Context->tree; h; h = h->next) {
297 for (c = h; !c->message; c = c->child);
298 mutt_uncollapse_thread (Context, c->message);
300 mutt_set_virtual (Context);
303 for (j = 0; j < Context->msgcount - oldcount; j++) {
306 for (k = 0; k < Context->msgcount; k++) {
307 HEADER *h = Context->hdrs[k];
309 if (h == save_new[j] && (!Context->pattern || h->limited))
310 mutt_uncollapse_thread (Context, h);
314 mutt_set_virtual (Context);
320 /* restore the current message to the message it was pointing to */
321 for (j = 0; j < Context->vcount; j++) {
322 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
329 if (menu->current < 0)
330 menu->current = ci_first_message ();
333 static void resort_index (MUTTMENU * menu)
336 HEADER *current = CURHDR;
339 mutt_sort_headers (Context, 0);
340 /* Restore the current message */
342 for (i = 0; i < Context->vcount; i++) {
343 if (Context->hdrs[Context->v2r[i]] == current) {
349 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
350 menu->current = mutt_parent_message (Context, current);
352 if (menu->current < 0)
353 menu->current = ci_first_message ();
355 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
358 struct mapping_t IndexHelp[] = {
359 {N_("Quit"), OP_QUIT},
360 {N_("Del"), OP_DELETE},
361 {N_("Undel"), OP_UNDELETE},
362 {N_("Save"), OP_SAVE},
363 {N_("Mail"), OP_MAIL},
364 {N_("Reply"), OP_REPLY},
365 {N_("Group"), OP_GROUP_REPLY},
366 {N_("Help"), OP_HELP},
371 struct mapping_t IndexNewsHelp[] = {
372 {N_("Quit"), OP_QUIT},
373 {N_("Del"), OP_DELETE},
374 {N_("Undel"), OP_UNDELETE},
375 {N_("Save"), OP_SAVE},
376 {N_("Post"), OP_POST},
377 {N_("Followup"), OP_FOLLOWUP},
378 {N_("Catchup"), OP_CATCHUP},
379 {N_("Help"), OP_HELP},
384 /* This function handles the message index window as well as commands returned
385 * from the pager (MENU_PAGER).
387 int mutt_index_menu (void)
389 char buf[LONG_STRING], helpstr[STRING];
392 int done = 0; /* controls when to exit the "event" loop */
394 int tag = 0; /* has the tag-prefix command been pressed? */
399 char *cp; /* temporary variable. */
400 int index_hint; /* used to restore cursor position */
401 int do_buffy_notify = 1;
402 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
403 int attach_msg = option (OPTATTACHMSG);
405 menu = mutt_new_menu ();
406 menu->menu = MENU_MAIN;
408 menu->pagelen = LINES - 3;
409 menu->make_entry = (void *) index_make_entry;
410 menu->color = index_color;
411 menu->current = ci_first_message ();
412 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
415 && (Context->magic ==
416 M_NNTP)) ? IndexNewsHelp :
421 buffy_check (0); /* force the buffy check after we enter the folder */
422 /* record folder we open to place sidebar indicator properly */
423 if (Context && Context->path)
424 sidebar_set_current (Context->path);
428 tag = 0; /* clear the tag-prefix */
430 menu->max = Context ? Context->vcount : 0;
431 oldcount = Context ? Context->msgcount : 0;
433 /* check if we need to resort the index because just about
434 * any 'op' below could do mutt_enter_command(), either here or
435 * from any new menu launched, and change $sort/$sort_aux
437 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
440 if (option (OPTREDRAWTREE) && Context && Context->msgcount
441 && (Sort & SORT_MASK) == SORT_THREADS) {
442 mutt_draw_tree (Context);
443 menu->redraw |= REDRAW_STATUS;
444 unset_option (OPTREDRAWTREE);
447 if (Context && !attach_msg) {
450 /* check for new mail in the mailbox. If nonzero, then something has
451 * changed about the file (either we got new mail or the file was
452 * modified underneath us.)
455 imap_allow_reopen (Context);
457 index_hint = (Context->vcount && menu->current >= 0
458 && menu->current < Context->vcount) ? CURHDR->index : 0;
460 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
461 if (!Context->path) {
462 /* fatal error occurred */
464 menu->redraw = REDRAW_FULL;
466 set_option (OPTSEARCHINVALID);
468 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
469 update_index (menu, Context, check, oldcount, index_hint);
471 /* notify the user of new mail */
472 if (check == M_REOPENED)
474 ("Mailbox was externally modified. Flags may be wrong."));
475 else if (check == M_NEW_MAIL) {
476 /* on new mail: redraw sidebar */
478 mutt_message (_("New mail in this mailbox."));
480 if (option (OPTBEEPNEW))
483 else if (check == M_FLAGS)
484 mutt_message (_("Mailbox was externally modified."));
486 /* avoid the message being overwritten by buffy */
489 menu->redraw = REDRAW_FULL;
490 menu->max = Context->vcount;
492 set_option (OPTSEARCHINVALID);
497 imap_disallow_reopen (Context);
500 /* check for new mail in the incoming folders */
502 if ((newcount = buffy_check (0)) != oldcount) {
503 menu->redraw |= REDRAW_STATUS;
504 menu->redraw |= REDRAW_SIDEBAR;
506 if (do_buffy_notify) {
507 if (buffy_notify () && option (OPTBEEPNEW))
516 if (menu->redraw & REDRAW_SIDEBAR)
518 if (menu->redraw & REDRAW_FULL) {
519 menu_redraw_full (menu);
524 if (menu->menu == MENU_MAIN) {
525 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
526 menu_check_recenter (menu);
528 if (menu->redraw & REDRAW_INDEX) {
529 menu_redraw_index (menu);
530 menu->redraw |= REDRAW_STATUS;
532 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
533 menu_redraw_motion (menu);
534 else if (menu->redraw & REDRAW_CURRENT)
535 menu_redraw_current (menu);
538 if (menu->redraw & REDRAW_STATUS) {
539 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
540 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
541 sidebar_draw_frames();
542 SETCOLOR (MT_COLOR_STATUS);
543 BKGDSET (MT_COLOR_STATUS);
544 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
545 mutt_paddstr (COLS-SW, buf);
546 SETCOLOR (MT_COLOR_NORMAL);
547 BKGDSET (MT_COLOR_NORMAL);
548 sidebar_set_buffystats (Context);
549 menu->redraw &= ~REDRAW_STATUS;
550 if (option (OPTXTERMSETTITLES)) {
551 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermTitle));
552 printf("\033]2;%s\007", buf);
553 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermIcon));
554 printf("\033]1;%s\007", 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 (m_strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
929 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
930 Context->pattern ? Context->pattern : ".*");
931 set_option (OPTHIDEREAD);
934 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
935 if (m_strncmp (buf, ".*", 2) == 0)
936 snprintf (buf, sizeof (buf), "~A");
937 unset_option (OPTHIDEREAD);
939 p_delete(&Context->pattern);
940 Context->pattern = m_strdup(buf);
942 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
943 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
945 if (menu->oldcurrent >= 0) {
946 /* try to find what used to be the current message */
948 for (i = 0; i < Context->vcount; i++)
949 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
953 if (menu->current < 0)
958 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
959 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
960 mutt_draw_tree (Context);
961 menu->redraw = REDRAW_FULL;
963 if (Context->pattern)
964 mutt_message _("To view all messages, limit to \"all\".");
975 if (query_quadoption (OPT_QUIT, _("Quit Madmutt?")) == M_YES) {
978 oldcount = Context ? Context->msgcount : 0;
981 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
984 if (check == M_NEW_MAIL || check == M_REOPENED)
985 update_index (menu, Context, check, oldcount, index_hint);
987 menu->redraw = REDRAW_FULL; /* new mail arrived? */
988 set_option (OPTSEARCHINVALID);
995 clearok (stdscr, TRUE);
996 menu->redraw = REDRAW_FULL;
1000 case OP_SEARCH_REVERSE:
1001 case OP_SEARCH_NEXT:
1002 case OP_SEARCH_OPPOSITE:
1006 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1007 menu->current = menu->oldcurrent;
1009 menu->redraw = REDRAW_MOTION;
1013 case OP_SORT_REVERSE:
1015 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1016 if (Context && Context->msgcount) {
1017 resort_index (menu);
1018 set_option (OPTSEARCHINVALID);
1027 if (tag && !option (OPTAUTOTAG)) {
1028 for (j = 0; j < Context->vcount; j++)
1029 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1030 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1033 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1034 Context->last_tag = CURHDR->tagged ? CURHDR :
1035 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1036 ? NULL : Context->last_tag);
1037 menu->redraw = REDRAW_STATUS;
1038 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1040 menu->redraw |= REDRAW_MOTION_RESYNCH;
1043 menu->redraw |= REDRAW_CURRENT;
1047 case OP_MAIN_TAG_PATTERN:
1051 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1052 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1055 case OP_MAIN_UNDELETE_PATTERN:
1061 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1063 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1065 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1068 case OP_MAIN_UNTAG_PATTERN:
1072 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1073 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1076 /* --------------------------------------------------------------------
1077 * The following operations can be performed inside of the pager.
1080 case OP_MAIN_IMAP_FETCH:
1081 if (Context->magic == M_IMAP)
1082 imap_check_mailbox (Context, &index_hint, 1);
1085 case OP_MAIN_SYNC_FOLDER:
1087 if (Context && !Context->msgcount)
1094 int oldvcount = Context->vcount;
1095 oldcount = Context->msgcount;
1099 /* calculate the number of messages _above_ the cursor,
1100 * so we can keep the cursor on the current message
1102 for (j = 0; j <= menu->current; j++) {
1103 if (Context->hdrs[Context->v2r[j]]->deleted)
1107 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1108 if (Context->vcount != oldvcount)
1109 menu->current -= dcount;
1110 set_option (OPTSEARCHINVALID);
1112 else if (check == M_NEW_MAIL || check == M_REOPENED)
1113 update_index (menu, Context, check, oldcount, index_hint);
1116 * do a sanity check even if mx_sync_mailbox failed.
1119 if (menu->current < 0 || menu->current >= Context->vcount)
1120 menu->current = ci_first_message ();
1123 /* check for a fatal error, or all messages deleted */
1127 /* if we were in the pager, redisplay the message */
1128 if (menu->menu == MENU_PAGER) {
1129 op = OP_DISPLAY_MESSAGE;
1133 menu->redraw = REDRAW_FULL;
1136 case OP_SIDEBAR_OPEN:
1137 case OP_MAIN_CHANGE_FOLDER:
1138 case OP_MAIN_CHANGE_FOLDER_READONLY:
1140 case OP_MAIN_CHANGE_GROUP:
1141 case OP_MAIN_CHANGE_GROUP_READONLY:
1143 if (attach_msg || option (OPTREADONLY) ||
1145 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1147 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1153 cp = _("Open mailbox in read-only mode");
1155 cp = _("Open mailbox");
1159 unset_option (OPTNEWS);
1160 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1161 set_option (OPTNEWS);
1162 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1165 cp = _("Open newsgroup in read-only mode");
1167 cp = _("Open newsgroup");
1168 nntp_buffy (buf, sizeof (buf));
1173 if (Context && Context->path)
1174 m_strcpy(buf, sizeof(buf), Context->path);
1175 if (op != OP_SIDEBAR_OPEN)
1176 buffy_next (buf, sizeof (buf));
1179 if (op == OP_SIDEBAR_OPEN) {
1180 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1182 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1183 if (menu->menu == MENU_PAGER) {
1184 op = OP_DISPLAY_MESSAGE;
1190 CLEARLINE (LINES - 1);
1195 if (option (OPTNEWS)) {
1196 unset_option (OPTNEWS);
1197 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1201 mutt_expand_path (buf, sizeof (buf));
1202 if (mx_get_magic (buf) <= 0) {
1203 mutt_error (_("%s is not a mailbox."), buf);
1206 m_strreplace(&CurrentFolder, buf);
1211 if (Context->cinfo && Context->realpath)
1212 m_strreplace(&LastFolder, Context->realpath);
1214 m_strreplace(&LastFolder, Context->path);
1215 oldcount = Context ? Context->msgcount : 0;
1217 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1218 if (check == M_NEW_MAIL || check == M_REOPENED)
1219 update_index (menu, Context, check, oldcount, index_hint);
1221 set_option (OPTSEARCHINVALID);
1222 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1230 /* Set CurrentMenu to MENU_MAIN before executing any folder
1231 * hooks so that all the index menu functions are available to
1235 CurrentMenu = MENU_MAIN;
1236 mutt_folder_hook (buf);
1238 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1239 menu->current = ci_first_message ();
1243 sidebar_set_current (buf);
1246 /* buffy_check() must be done with mail-reader mode! */
1247 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1249 && (Context->magic ==
1250 M_NNTP)) ? IndexNewsHelp :
1253 mutt_clear_error ();
1254 buffy_check (0); /* force the buffy check after we have changed
1256 menu->redraw = REDRAW_FULL;
1257 set_option (OPTSEARCHINVALID);
1260 case OP_DISPLAY_MESSAGE:
1261 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1266 * toggle the weeding of headers so that a user can press the key
1267 * again while reading the message.
1269 if (op == OP_DISPLAY_HEADERS)
1270 toggle_option (OPTWEED);
1272 unset_option (OPTNEEDRESORT);
1274 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1275 mutt_uncollapse_thread (Context, CURHDR);
1276 mutt_set_virtual (Context);
1277 if (option (OPTUNCOLLAPSEJUMP))
1278 menu->current = mutt_thread_next_unread (Context, CURHDR);
1281 if (option (OPTPGPAUTODEC) &&
1282 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1283 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1285 if ((op = mutt_display_message (CURHDR)) == -1) {
1286 unset_option (OPTNEEDRESORT);
1290 menu->menu = MENU_PAGER;
1291 menu->oldcurrent = menu->current;
1297 if (menu->menu == MENU_MAIN && attach_msg) {
1302 if ((menu->menu == MENU_MAIN)
1303 && (query_quadoption (OPT_QUIT,
1304 _("Exit Madmutt without saving?")) == M_YES))
1307 mx_fastclose_mailbox (Context);
1319 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1320 /* if we were in the pager, redisplay the message */
1321 if (menu->menu == MENU_PAGER) {
1322 op = OP_DISPLAY_MESSAGE;
1326 menu->redraw = REDRAW_CURRENT;
1329 case OP_MAIN_BREAK_THREAD:
1335 if ((Sort & SORT_MASK) != SORT_THREADS)
1336 mutt_error (_("Threading is not enabled."));
1340 HEADER *oldcur = CURHDR;
1342 mutt_break_thread (CURHDR);
1343 mutt_sort_headers (Context, 1);
1344 menu->current = oldcur->virtual;
1347 Context->changed = 1;
1348 mutt_message _("Thread broken");
1350 if (menu->menu == MENU_PAGER) {
1351 op = OP_DISPLAY_MESSAGE;
1355 menu->redraw |= REDRAW_INDEX;
1359 case OP_MAIN_LINK_THREADS:
1365 if ((Sort & SORT_MASK) != SORT_THREADS)
1366 mutt_error (_("Threading is not enabled."));
1368 else if (!CURHDR->env->message_id)
1369 mutt_error (_("No Message-ID: header available to link thread"));
1371 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1372 mutt_error (_("First, please tag a message to be linked here"));
1375 HEADER *oldcur = CURHDR;
1377 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1379 mutt_sort_headers (Context, 1);
1380 menu->current = oldcur->virtual;
1382 Context->changed = 1;
1383 mutt_message _("Threads linked");
1386 mutt_error (_("No thread linked"));
1389 if (menu->menu == MENU_PAGER) {
1390 op = OP_DISPLAY_MESSAGE;
1394 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1397 case OP_MAIN_NEXT_UNDELETED:
1401 if (menu->current >= Context->vcount - 1) {
1402 if (menu->menu == MENU_MAIN)
1403 mutt_error (_("You are on the last message."));
1407 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1408 menu->current = menu->oldcurrent;
1409 if (menu->menu == MENU_MAIN)
1410 mutt_error (_("No undeleted messages."));
1412 else if (menu->menu == MENU_PAGER) {
1413 op = OP_DISPLAY_MESSAGE;
1417 menu->redraw = REDRAW_MOTION;
1424 if (menu->current >= Context->vcount - 1) {
1425 if (menu->menu == MENU_MAIN)
1426 mutt_error (_("You are on the last message."));
1431 if (menu->menu == MENU_PAGER) {
1432 op = OP_DISPLAY_MESSAGE;
1436 menu->redraw = REDRAW_MOTION;
1439 case OP_MAIN_PREV_UNDELETED:
1443 if (menu->current < 1) {
1444 mutt_error (_("You are on the first message."));
1448 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1449 menu->current = menu->oldcurrent;
1450 if (menu->menu == MENU_MAIN)
1451 mutt_error (_("No undeleted messages."));
1453 else if (menu->menu == MENU_PAGER) {
1454 op = OP_DISPLAY_MESSAGE;
1458 menu->redraw = REDRAW_MOTION;
1465 if (menu->current < 1) {
1466 if (menu->menu == MENU_MAIN)
1467 mutt_error (_("You are on the first message."));
1472 if (menu->menu == MENU_PAGER) {
1473 op = OP_DISPLAY_MESSAGE;
1477 menu->redraw = REDRAW_MOTION;
1480 case OP_DECRYPT_COPY:
1481 case OP_DECRYPT_SAVE:
1482 case OP_COPY_MESSAGE:
1484 case OP_DECODE_COPY:
1485 case OP_DECODE_SAVE:
1488 if (mutt_save_message (tag ? NULL : CURHDR,
1489 (op == OP_DECRYPT_SAVE) ||
1490 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1491 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1492 (op == OP_DECRYPT_SAVE)
1493 || (op == OP_DECRYPT_COPY)
1494 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1501 menu->redraw |= REDRAW_INDEX;
1502 else if (option (OPTRESOLVE)) {
1503 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1504 menu->current = menu->oldcurrent;
1505 menu->redraw |= REDRAW_CURRENT;
1508 menu->redraw |= REDRAW_MOTION_RESYNCH;
1511 menu->redraw |= REDRAW_CURRENT;
1515 case OP_MAIN_NEXT_NEW:
1516 case OP_MAIN_NEXT_UNREAD:
1517 case OP_MAIN_PREV_NEW:
1518 case OP_MAIN_PREV_UNREAD:
1519 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1520 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1523 int first_unread = -1;
1531 for (j = 0; j != Context->vcount; j++) {
1532 #define CURHDRi Context->hdrs[Context->v2r[i]]
1533 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1534 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1536 if (i > Context->vcount - 1) {
1537 mutt_message _("Search wrapped to top.");
1545 mutt_message _("Search wrapped to bottom.");
1547 i = Context->vcount - 1;
1551 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1552 if (UNREAD (CURHDRi) && first_unread == -1)
1554 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1557 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1558 if (first_unread == -1)
1560 if ((!CURHDRi->old) && first_new == -1)
1564 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1567 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1568 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1569 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1574 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1575 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1576 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1578 menu->current = first_new;
1579 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1580 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1581 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1582 && first_unread != -1)
1583 menu->current = first_unread;
1585 if (menu->current == -1) {
1586 menu->current = menu->oldcurrent;
1587 mutt_error ("%s%s.",
1588 (op == OP_MAIN_NEXT_NEW
1590 OP_MAIN_PREV_NEW) ? _("No new messages") :
1591 _("No unread messages"),
1592 Context->pattern ? _(" in this limited view") : "");
1594 else if (menu->menu == MENU_PAGER) {
1595 op = OP_DISPLAY_MESSAGE;
1599 menu->redraw = REDRAW_MOTION;
1602 case OP_FLAG_MESSAGE:
1608 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1611 for (j = 0; j < Context->vcount; j++) {
1612 if (Context->hdrs[Context->v2r[j]]->tagged)
1613 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1614 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1617 menu->redraw |= REDRAW_INDEX;
1620 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1621 if (option (OPTRESOLVE)) {
1622 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1623 menu->current = menu->oldcurrent;
1624 menu->redraw = REDRAW_CURRENT;
1627 menu->redraw = REDRAW_MOTION_RESYNCH;
1630 menu->redraw = REDRAW_CURRENT;
1632 menu->redraw |= REDRAW_STATUS;
1641 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1644 for (j = 0; j < Context->vcount; j++) {
1645 if (Context->hdrs[Context->v2r[j]]->tagged) {
1646 if (Context->hdrs[Context->v2r[j]]->read ||
1647 Context->hdrs[Context->v2r[j]]->old)
1648 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1651 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1655 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1658 if (CURHDR->read || CURHDR->old)
1659 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1661 mutt_set_flag (Context, CURHDR, M_READ, 1);
1663 if (option (OPTRESOLVE)) {
1664 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1665 menu->current = menu->oldcurrent;
1666 menu->redraw = REDRAW_CURRENT;
1669 menu->redraw = REDRAW_MOTION_RESYNCH;
1672 menu->redraw = REDRAW_CURRENT;
1673 menu->redraw |= REDRAW_STATUS;
1677 case OP_TOGGLE_WRITE:
1680 if (mx_toggle_write (Context) == 0)
1681 menu->redraw |= REDRAW_STATUS;
1684 case OP_MAIN_NEXT_THREAD:
1685 case OP_MAIN_NEXT_SUBTHREAD:
1686 case OP_MAIN_PREV_THREAD:
1687 case OP_MAIN_PREV_SUBTHREAD:
1692 case OP_MAIN_NEXT_THREAD:
1693 menu->current = mutt_next_thread (CURHDR);
1696 case OP_MAIN_NEXT_SUBTHREAD:
1697 menu->current = mutt_next_subthread (CURHDR);
1700 case OP_MAIN_PREV_THREAD:
1701 menu->current = mutt_previous_thread (CURHDR);
1704 case OP_MAIN_PREV_SUBTHREAD:
1705 menu->current = mutt_previous_subthread (CURHDR);
1709 if (menu->current < 0) {
1710 menu->current = menu->oldcurrent;
1711 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1712 mutt_error (_("No more threads."));
1715 mutt_error (_("You are on the first thread."));
1717 else if (menu->menu == MENU_PAGER) {
1718 op = OP_DISPLAY_MESSAGE;
1722 menu->redraw = REDRAW_MOTION;
1725 case OP_MAIN_PARENT_MESSAGE:
1730 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1731 menu->current = menu->oldcurrent;
1733 else if (menu->menu == MENU_PAGER) {
1734 op = OP_DISPLAY_MESSAGE;
1738 menu->redraw = REDRAW_MOTION;
1741 case OP_MAIN_SET_FLAG:
1742 case OP_MAIN_CLEAR_FLAG:
1748 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1750 menu->redraw = REDRAW_STATUS;
1752 menu->redraw |= REDRAW_INDEX;
1753 else if (option (OPTRESOLVE)) {
1754 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1755 menu->current = menu->oldcurrent;
1756 menu->redraw |= REDRAW_CURRENT;
1759 menu->redraw |= REDRAW_MOTION_RESYNCH;
1762 menu->redraw |= REDRAW_CURRENT;
1766 case OP_MAIN_COLLAPSE_THREAD:
1770 if ((Sort & SORT_MASK) != SORT_THREADS) {
1771 mutt_error (_("Threading is not enabled."));
1776 if (CURHDR->collapsed) {
1777 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1778 mutt_set_virtual (Context);
1779 if (option (OPTUNCOLLAPSEJUMP))
1780 menu->current = mutt_thread_next_unread (Context, CURHDR);
1782 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1783 menu->current = mutt_collapse_thread (Context, CURHDR);
1784 mutt_set_virtual (Context);
1787 mutt_error (_("Thread contains unread messages."));
1792 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1796 case OP_MAIN_COLLAPSE_ALL:
1800 if ((Sort & SORT_MASK) != SORT_THREADS) {
1801 mutt_error (_("Threading is not enabled."));
1808 THREAD *thread, *top;
1811 if (CURHDR->collapsed)
1812 final = mutt_uncollapse_thread (Context, CURHDR);
1813 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1814 final = mutt_collapse_thread (Context, CURHDR);
1816 final = CURHDR->virtual;
1818 base = Context->hdrs[Context->v2r[final]];
1820 top = Context->tree;
1821 Context->collapsed = !Context->collapsed;
1822 while ((thread = top) != NULL) {
1823 while (!thread->message)
1824 thread = thread->child;
1825 h = thread->message;
1827 if (h->collapsed != Context->collapsed) {
1829 mutt_uncollapse_thread (Context, h);
1830 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1831 mutt_collapse_thread (Context, h);
1836 mutt_set_virtual (Context);
1837 for (j = 0; j < Context->vcount; j++) {
1838 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1844 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1848 /* --------------------------------------------------------------------
1849 * These functions are invoked directly from the internal-pager
1852 case OP_BOUNCE_MESSAGE:
1857 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1860 case OP_CREATE_ALIAS:
1862 mutt_create_alias (Context
1863 && Context->vcount ? CURHDR->env : NULL, NULL);
1864 MAYBE_REDRAW (menu->redraw);
1865 menu->redraw |= REDRAW_CURRENT;
1870 mutt_query_menu (NULL, 0);
1871 MAYBE_REDRAW (menu->redraw);
1874 case OP_PURGE_MESSAGE:
1881 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1884 mutt_tag_set_flag (M_DELETE, 1);
1885 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1886 if (option (OPTDELETEUNTAG))
1887 mutt_tag_set_flag (M_TAG, 0);
1888 menu->redraw = REDRAW_INDEX;
1891 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1892 mutt_set_flag (Context, CURHDR, M_PURGED,
1893 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1894 if (option (OPTDELETEUNTAG))
1895 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1896 if (option (OPTRESOLVE)) {
1897 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1898 menu->current = menu->oldcurrent;
1899 menu->redraw = REDRAW_CURRENT;
1901 else if (menu->menu == MENU_PAGER) {
1902 op = OP_DISPLAY_MESSAGE;
1906 menu->redraw |= REDRAW_MOTION_RESYNCH;
1909 menu->redraw = REDRAW_CURRENT;
1911 menu->redraw |= REDRAW_STATUS;
1914 case OP_DELETE_THREAD:
1915 case OP_DELETE_SUBTHREAD:
1921 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1923 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1924 op == OP_DELETE_THREAD ? 0 : 1);
1927 if (option (OPTDELETEUNTAG))
1928 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1929 op == OP_DELETE_THREAD ? 0 : 1);
1930 if (option (OPTRESOLVE))
1931 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1932 menu->current = menu->oldcurrent;
1933 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1939 if (Context && Context->magic == M_NNTP) {
1940 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1941 ((NNTP_DATA *) Context->data)->group))
1942 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1947 case OP_DISPLAY_ADDRESS:
1951 mutt_display_address (CURHDR->env);
1954 case OP_ENTER_COMMAND:
1956 CurrentMenu = MENU_MAIN;
1957 mutt_enter_command ();
1958 mutt_check_rescore (Context);
1959 if (option (OPTFORCEREDRAWINDEX))
1960 menu->redraw = REDRAW_FULL;
1961 unset_option (OPTFORCEREDRAWINDEX);
1962 unset_option (OPTFORCEREDRAWPAGER);
1965 case OP_EDIT_MESSAGE:
1972 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1974 if (option (OPTPGPAUTODEC)
1975 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1976 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1977 mutt_edit_message (Context, tag ? NULL : CURHDR);
1978 menu->redraw = REDRAW_FULL;
1982 case OP_FORWARD_MESSAGE:
1988 if (option (OPTPGPAUTODEC) &&
1989 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1990 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1991 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
1992 menu->redraw = REDRAW_FULL;
1996 case OP_FORGET_PASSPHRASE:
1997 crypt_forget_passphrase ();
2000 case OP_GROUP_REPLY:
2006 if (option (OPTPGPAUTODEC) &&
2007 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2008 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2010 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2011 tag ? NULL : CURHDR);
2012 menu->redraw = REDRAW_FULL;
2021 if (option (OPTPGPAUTODEC) &&
2022 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2023 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2025 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2026 tag ? NULL : CURHDR);
2027 menu->redraw = REDRAW_FULL;
2033 ci_send_message (0, NULL, NULL, Context, NULL);
2034 menu->redraw = REDRAW_FULL;
2039 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2040 menu->redraw = REDRAW_FULL;
2044 case OP_EXTRACT_KEYS:
2047 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2048 menu->redraw = REDRAW_FULL;
2052 case OP_CHECK_TRADITIONAL:
2055 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2056 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2058 if (menu->menu == MENU_PAGER) {
2059 op = OP_DISPLAY_MESSAGE;
2068 mutt_pipe_message (tag ? NULL : CURHDR);
2069 /* in an IMAP folder index with imap_peek=no, piping could change
2070 * * new or old messages status to read. Redraw what's needed.
2072 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2073 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2075 MAYBE_REDRAW (menu->redraw);
2082 mutt_print_message (tag ? NULL : CURHDR);
2083 /* in an IMAP folder index with imap_peek=no, piping could change
2084 * * new or old messages status to read. Redraw what's needed.
2086 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2087 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2091 case OP_MAIN_READ_THREAD:
2092 case OP_MAIN_READ_SUBTHREAD:
2098 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2100 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2101 op == OP_MAIN_READ_THREAD ? 0 : 1);
2104 if (option (OPTRESOLVE)) {
2105 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2106 mutt_next_thread (CURHDR) :
2107 mutt_next_subthread (CURHDR))) == -1)
2108 menu->current = menu->oldcurrent;
2110 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2114 case OP_RECALL_MESSAGE:
2117 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2118 menu->redraw = REDRAW_FULL;
2128 for (j = 0; j < Context->vcount; j++) {
2129 if (Context->hdrs[Context->v2r[j]]->tagged)
2130 mutt_resend_message (NULL, Context,
2131 Context->hdrs[Context->v2r[j]]);
2135 mutt_resend_message (NULL, Context, CURHDR);
2137 menu->redraw = REDRAW_FULL;
2143 case OP_FORWARD_TO_GROUP:
2146 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2147 Context && Context->msgcount == 0) {
2148 mutt_error (_("There are no messages."));
2151 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2152 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2153 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2154 _("Reply by mail as poster prefers?")) !=
2156 if (Context && Context->magic == M_NNTP
2157 && !((NNTP_DATA *) Context->data)->allowed
2158 && query_quadoption (OPT_TOMODERATED,
2160 ("Posting to this group not allowed, may be moderated. Continue?"))
2164 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2167 if (op == OP_FOLLOWUP)
2168 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2169 tag ? NULL : CURHDR);
2171 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2172 tag ? NULL : CURHDR);
2174 menu->redraw = REDRAW_FULL;
2185 if (option (OPTPGPAUTODEC) &&
2186 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2187 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2189 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2190 menu->redraw = REDRAW_FULL;
2193 case OP_SHELL_ESCAPE:
2195 mutt_shell_escape ();
2196 MAYBE_REDRAW (menu->redraw);
2200 case OP_TAG_SUBTHREAD:
2204 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2205 op == OP_TAG_THREAD ? 0 : 1);
2208 if (option (OPTRESOLVE)) {
2209 menu->current = mutt_next_thread (CURHDR);
2211 if (menu->current == -1)
2212 menu->current = menu->oldcurrent;
2214 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2224 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2227 mutt_tag_set_flag (M_DELETE, 0);
2228 mutt_tag_set_flag (M_PURGED, 0);
2229 menu->redraw = REDRAW_INDEX;
2232 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2233 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2234 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2236 menu->redraw = REDRAW_MOTION_RESYNCH;
2239 menu->redraw = REDRAW_CURRENT;
2241 menu->redraw |= REDRAW_STATUS;
2244 case OP_UNDELETE_THREAD:
2245 case OP_UNDELETE_SUBTHREAD:
2251 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2253 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2254 op == OP_UNDELETE_THREAD ? 0 : 1)
2255 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2256 op == OP_UNDELETE_THREAD ? 0 : 1);
2259 if (option (OPTRESOLVE)) {
2260 if (op == OP_UNDELETE_THREAD)
2261 menu->current = mutt_next_thread (CURHDR);
2263 menu->current = mutt_next_subthread (CURHDR);
2265 if (menu->current == -1)
2266 menu->current = menu->oldcurrent;
2268 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2277 if (option (OPTFORCEBUFFYCHECK))
2280 menu->redraw = REDRAW_FULL;
2283 case OP_VIEW_ATTACHMENTS:
2286 mutt_view_attachments (CURHDR);
2287 if (CURHDR->attach_del)
2288 Context->changed = 1;
2289 menu->redraw = REDRAW_FULL;
2299 case OP_REBUILD_CACHE:
2300 mx_rebuild_cache ();
2303 case OP_SIDEBAR_SCROLL_UP:
2304 case OP_SIDEBAR_SCROLL_DOWN:
2305 case OP_SIDEBAR_NEXT:
2306 case OP_SIDEBAR_PREV:
2307 case OP_SIDEBAR_NEXT_NEW:
2308 case OP_SIDEBAR_PREV_NEW:
2309 sidebar_scroll (op);
2312 if (menu->menu == MENU_MAIN)
2313 km_error_key (MENU_MAIN);
2316 if (menu->menu == MENU_PAGER) {
2317 menu->menu = MENU_MAIN;
2318 menu->redraw = REDRAW_FULL;
2326 /* Close all open IMAP connections */
2329 /* Close all open NNTP connections */
2337 mutt_menuDestroy (&menu);
2341 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2348 for (color = ColorIndexList; color; color = color->next)
2349 if (mutt_pattern_exec
2350 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2351 curhdr->pair = color->pair;
2354 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];