2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * Parts were written/modified by:
6 * Nico Golde <nico@ngolde.de>
8 * This file is part of mutt-ng, see http://www.muttng.org/.
9 * It's licensed under the GNU General Public License,
10 * please see the file GPL in the top level source directory.
13 #include <lib-lib/lib-lib.h>
15 #include <lib-ui/sidebar.h>
16 #include <lib-mx/mx.h>
27 #include "recvattach.h"
31 #include <imap/imap_private.h>
34 #include <nntp/nntp.h>
38 #include "mutt_sasl.h"
41 static const char *No_mailbox_is_open = N_("No mailbox is open.");
42 static const char *There_are_no_messages = N_("There are no messages.");
43 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
44 static const char *Function_not_permitted_in_attach_message_mode =
45 N_("Function not permitted in attach-message mode.");
46 static const char *No_visible = N_("No visible messages.");
48 #define CHECK_IN_MAILBOX if (!Context) \
51 mutt_error (_(No_mailbox_is_open)); \
55 #define CHECK_MSGCOUNT if (!Context) \
58 mutt_error(_(No_mailbox_is_open)); \
61 else if (!Context->msgcount) \
64 mutt_error(_(There_are_no_messages)); \
68 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
71 mutt_error(_(No_visible)); \
76 #define CHECK_READONLY if (Context->readonly) \
79 mutt_error(_(Mailbox_is_read_only)); \
83 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
86 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
90 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
91 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
92 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
93 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
95 extern size_t UngetCount;
97 void index_make_entry (char *s, ssize_t l, struct menu_t * menu, int num)
99 format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_INDEX;
100 int edgemsgno, reverse = Sort & SORT_REVERSE;
101 HEADER *h = Context->hdrs[Context->v2r[num]];
104 if (option(OPTARROWCURSOR))
105 flag |= M_FORMAT_ARROWCURSOR;
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[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."));
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 () && MCore.beep_new)
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 printf("\033]2;%s\007", buf);
554 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermIcon));
555 printf("\033]1;%s\007", buf);
561 if (menu->current < menu->max)
562 menu->oldcurrent = menu->current;
564 menu->oldcurrent = -1;
566 if (option (OPTARROWCURSOR))
567 move (menu->current - menu->top + menu->offset, 2);
568 else if (option (OPTBRAILLEFRIENDLY))
569 move (menu->current - menu->top + menu->offset, 0);
571 move (menu->current - menu->top + menu->offset, COLS - 1);
574 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
577 mutt_resize_screen ();
578 menu->redraw = REDRAW_FULL;
579 menu->menu = MENU_MAIN;
581 menu->top = 0; /* so we scroll the right amount */
583 * force a real complete redraw. clrtobot() doesn't seem to be able
584 * to handle every case without this.
586 clearok (stdscr, TRUE);
591 op = km_dokey (MENU_MAIN);
594 continue; /* either user abort or timeout */
598 /* special handling for the tag-prefix function */
599 if (op == OP_TAG_PREFIX) {
601 mutt_error (_("No mailbox is open."));
606 if (!Context->tagged) {
607 mutt_error (_("No tagged messages."));
613 /* give visual indication that the next command is a tag- command */
614 mvaddstr (LINES - 1, 0, "tag-");
617 /* get the real command */
618 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
619 /* abort tag sequence */
620 CLEARLINE (LINES - 1);
624 else if (option (OPTAUTOTAG) && Context && Context->tagged)
627 if (op == OP_TAG_PREFIX_COND) {
629 mutt_error (_("No mailbox is open."));
634 if (!Context->tagged) {
637 while (UngetCount > 0) {
639 if (tmp.op == OP_END_COND)
642 mutt_message (_("Nothing to do."));
648 /* give visual indication that the next command is a tag- command */
649 mvaddstr (LINES - 1, 0, "tag-");
652 /* get the real command */
653 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
654 /* abort tag sequence */
655 CLEARLINE (LINES - 1);
663 if (menu->current < menu->max)
664 menu->oldcurrent = menu->current;
666 menu->oldcurrent = -1;
668 mutt_curs_set (1); /* fallback from the pager */
672 unset_option (OPTNEWS); /* for any case */
677 /* ----------------------------------------------------------------------
682 menu_bottom_page (menu);
685 menu_first_entry (menu);
688 menu_middle_page (menu);
694 menu_half_down (menu);
697 menu_next_line (menu);
700 menu_prev_line (menu);
703 menu_next_page (menu);
706 menu_prev_page (menu);
709 menu_last_entry (menu);
712 menu_top_page (menu);
715 menu_current_top (menu);
717 case OP_CURRENT_MIDDLE:
718 menu_current_middle (menu);
720 case OP_CURRENT_BOTTOM:
721 menu_current_bottom (menu);
728 if (Context->magic == M_NNTP) {
731 if (op == OP_GET_MESSAGE) {
733 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
738 string_list_t *ref = CURHDR->env->references;
741 mutt_error (_("Article has no parent reference!"));
745 m_strcpy(buf, sizeof(buf), ref->data);
747 if (!Context->id_hash)
748 Context->id_hash = mutt_make_id_hash (Context);
749 if ((h = hash_find (Context->id_hash, buf))) {
750 if (h->virtual != -1) {
751 menu->current = h->virtual;
752 menu->redraw = REDRAW_MOTION_RESYNCH;
754 else if (h->collapsed) {
755 mutt_uncollapse_thread (Context, h);
756 mutt_set_virtual (Context);
757 menu->current = h->virtual;
758 menu->redraw = REDRAW_MOTION_RESYNCH;
761 mutt_error (_("Message not visible in limited view."));
764 if (nntp_check_msgid (Context, buf) == 0) {
765 h = Context->hdrs[Context->msgcount - 1];
766 mutt_sort_headers (Context, 0);
767 menu->current = h->virtual;
768 menu->redraw = REDRAW_FULL;
771 mutt_error (_("Article %s not found on server"), buf);
776 case OP_GET_CHILDREN:
777 case OP_RECONSTRUCT_THREAD:
779 if (Context->magic == M_NNTP) {
781 int old = CURHDR->index;
783 if (!CURHDR->env->message_id) {
784 mutt_error (_("No Message-ID. Unable to perform operation"));
789 if (!Context->id_hash)
790 Context->id_hash = mutt_make_id_hash (Context);
791 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
793 if (op == OP_RECONSTRUCT_THREAD) {
794 string_list_t *ref = CURHDR->env->references;
797 nntp_check_msgid (Context, ref->data);
798 /* the last msgid in References is the root message */
800 m_strcpy(buf, sizeof(buf), ref->data);
804 mutt_message (_("Check for children of message..."));
806 if (nntp_check_children (Context, buf) == 0) {
807 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
808 h = hash_find (Context->id_hash, buf);
809 /* if the root message was retrieved, move to it */
811 menu->current = h->virtual;
812 else /* try to restore old position */
813 for (i = 0; i < Context->msgcount; i++)
814 if (Context->hdrs[i]->index == old) {
815 menu->current = Context->hdrs[i]->virtual;
816 /* As an added courtesy, recenter the menu
817 * with the current entry at the middle of the screen */
818 menu_check_recenter (menu);
819 menu_current_middle (menu);
822 menu->redraw = REDRAW_FULL;
832 if (isdigit (LastKey))
833 mutt_ungetch (LastKey, 0);
835 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
839 if (!isdigit ((unsigned char) buf[0])) {
840 mutt_error (_("Argument must be a message number."));
846 if (i > 0 && i <= Context->msgcount) {
847 for (j = i - 1; j < Context->msgcount; j++) {
848 if (Context->hdrs[j]->virtual != -1)
851 if (j >= Context->msgcount) {
852 for (j = i - 2; j >= 0; j--) {
853 if (Context->hdrs[j]->virtual != -1)
859 menu->current = Context->hdrs[j]->virtual;
860 if (menu->menu == MENU_PAGER) {
861 op = OP_DISPLAY_MESSAGE;
865 menu->redraw = REDRAW_MOTION;
868 mutt_error (_("That message is not visible."));
871 mutt_error (_("Invalid message number."));
875 /* --------------------------------------------------------------------
876 * `index' specific commands
879 case OP_MAIN_DELETE_PATTERN:
885 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
888 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
889 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
892 case OP_MAIN_FETCH_MAIL:
896 menu->redraw = REDRAW_FULL;
901 mutt_help (MENU_MAIN);
902 menu->redraw = REDRAW_FULL;
905 case OP_MAIN_SHOW_LIMIT:
907 if (!Context->pattern)
908 mutt_message (_("No limit pattern is in effect."));
913 /* i18n: ask for a limit to apply */
914 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
915 mutt_message ("%s", buffer);
923 menu->oldcurrent = (Context->vcount && menu->current >= 0
925 Context->vcount) ? CURHDR->index : -1;
926 if (op == OP_TOGGLE_READ) {
927 char buffer[LONG_STRING];
929 if (m_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 (m_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_quadoption2(MCore.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_quadoption2(MCore.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;
1996 case OP_GROUP_REPLY:
2002 if (option (OPTPGPAUTODEC) &&
2003 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2004 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2006 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2007 tag ? NULL : CURHDR);
2008 menu->redraw = REDRAW_FULL;
2017 if (option (OPTPGPAUTODEC) &&
2018 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2019 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2021 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2022 tag ? NULL : CURHDR);
2023 menu->redraw = REDRAW_FULL;
2029 ci_send_message (0, NULL, NULL, Context, NULL);
2030 menu->redraw = REDRAW_FULL;
2033 case OP_EXTRACT_KEYS:
2036 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2037 menu->redraw = REDRAW_FULL;
2041 case OP_CHECK_TRADITIONAL:
2044 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2045 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2047 if (menu->menu == MENU_PAGER) {
2048 op = OP_DISPLAY_MESSAGE;
2057 mutt_pipe_message (tag ? NULL : CURHDR);
2058 /* in an IMAP folder index with imap_peek=no, piping could change
2059 * * new or old messages status to read. Redraw what's needed.
2061 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2062 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2064 MAYBE_REDRAW (menu->redraw);
2071 mutt_print_message (tag ? NULL : CURHDR);
2072 /* in an IMAP folder index with imap_peek=no, piping could change
2073 * * new or old messages status to read. Redraw what's needed.
2075 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2076 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2080 case OP_MAIN_READ_THREAD:
2081 case OP_MAIN_READ_SUBTHREAD:
2087 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2089 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2090 op == OP_MAIN_READ_THREAD ? 0 : 1);
2093 if (option (OPTRESOLVE)) {
2094 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2095 mutt_next_thread (CURHDR) :
2096 mutt_next_subthread (CURHDR))) == -1)
2097 menu->current = menu->oldcurrent;
2099 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2103 case OP_RECALL_MESSAGE:
2106 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2107 menu->redraw = REDRAW_FULL;
2117 for (j = 0; j < Context->vcount; j++) {
2118 if (Context->hdrs[Context->v2r[j]]->tagged)
2119 mutt_resend_message (NULL, Context,
2120 Context->hdrs[Context->v2r[j]]);
2124 mutt_resend_message (NULL, Context, CURHDR);
2126 menu->redraw = REDRAW_FULL;
2132 case OP_FORWARD_TO_GROUP:
2135 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2136 Context && Context->msgcount == 0) {
2137 mutt_error (_("There are no messages."));
2140 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2141 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2142 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2143 _("Reply by mail as poster prefers?")) !=
2145 if (Context && Context->magic == M_NNTP
2146 && !((NNTP_DATA *) Context->data)->allowed
2147 && query_quadoption (OPT_TOMODERATED,
2149 ("Posting to this group not allowed, may be moderated. Continue?"))
2153 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2156 if (op == OP_FOLLOWUP)
2157 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2158 tag ? NULL : CURHDR);
2160 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2161 tag ? NULL : CURHDR);
2163 menu->redraw = REDRAW_FULL;
2174 if (option (OPTPGPAUTODEC) &&
2175 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2176 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2178 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2179 menu->redraw = REDRAW_FULL;
2182 case OP_SHELL_ESCAPE:
2184 mutt_shell_escape ();
2185 MAYBE_REDRAW (menu->redraw);
2189 case OP_TAG_SUBTHREAD:
2193 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2194 op == OP_TAG_THREAD ? 0 : 1);
2197 if (option (OPTRESOLVE)) {
2198 menu->current = mutt_next_thread (CURHDR);
2200 if (menu->current == -1)
2201 menu->current = menu->oldcurrent;
2203 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2213 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2216 mutt_tag_set_flag (M_DELETE, 0);
2217 mutt_tag_set_flag (M_PURGED, 0);
2218 menu->redraw = REDRAW_INDEX;
2221 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2222 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2223 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2225 menu->redraw = REDRAW_MOTION_RESYNCH;
2228 menu->redraw = REDRAW_CURRENT;
2230 menu->redraw |= REDRAW_STATUS;
2233 case OP_UNDELETE_THREAD:
2234 case OP_UNDELETE_SUBTHREAD:
2240 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2242 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2243 op == OP_UNDELETE_THREAD ? 0 : 1)
2244 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2245 op == OP_UNDELETE_THREAD ? 0 : 1);
2248 if (option (OPTRESOLVE)) {
2249 if (op == OP_UNDELETE_THREAD)
2250 menu->current = mutt_next_thread (CURHDR);
2252 menu->current = mutt_next_subthread (CURHDR);
2254 if (menu->current == -1)
2255 menu->current = menu->oldcurrent;
2257 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2266 if (option (OPTFORCEBUFFYCHECK))
2269 menu->redraw = REDRAW_FULL;
2272 case OP_VIEW_ATTACHMENTS:
2275 mutt_view_attachments (CURHDR);
2276 if (CURHDR->attach_del)
2277 Context->changed = 1;
2278 menu->redraw = REDRAW_FULL;
2288 case OP_REBUILD_CACHE:
2289 mx_rebuild_cache ();
2292 case OP_SIDEBAR_SCROLL_UP:
2293 case OP_SIDEBAR_SCROLL_DOWN:
2294 case OP_SIDEBAR_NEXT:
2295 case OP_SIDEBAR_PREV:
2296 case OP_SIDEBAR_NEXT_NEW:
2297 case OP_SIDEBAR_PREV_NEW:
2298 sidebar_scroll (op);
2301 if (menu->menu == MENU_MAIN)
2302 km_error_key (MENU_MAIN);
2305 if (menu->menu == MENU_PAGER) {
2306 menu->menu = MENU_MAIN;
2307 menu->redraw = REDRAW_FULL;
2315 /* Close all open IMAP connections */
2318 /* Close all open NNTP connections */
2326 mutt_menuDestroy (&menu);
2330 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2337 for (color = ColorIndexList; color; color = color->next)
2338 if (mutt_pattern_exec
2339 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2340 curhdr->pair = color->pair;
2343 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];