2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * This file is part of mutt-ng, see http://www.muttng.org/.
6 * It's licensed under the GNU General Public License,
7 * please see the file GPL in the top level source directory.
15 #include "mutt_curses.h"
17 #include "mutt_menu.h"
30 #include "imap_private.h"
33 #include "mutt_crypt.h"
48 static const char *No_mailbox_is_open = N_("No mailbox is open.");
49 static const char *There_are_no_messages = N_("There are no messages.");
50 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
51 static const char *Function_not_permitted_in_attach_message_mode =
52 N_("Function not permitted in attach-message mode.");
53 static const char *No_visible = N_("No visible messages.");
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)); \
84 /* the error message returned here could be better. */
85 #define CHECK_IMAP_ACL(aclbit) if (Context->magic == M_IMAP) \
86 if (mutt_bit_isset (((IMAP_DATA *)Context->data)->capabilities, ACL) \
87 && !mutt_bit_isset(((IMAP_DATA *)Context->data)->rights,aclbit)){ \
89 mutt_error ("Operation not permitted by the IMAP ACL for this mailbox"); \
94 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
97 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
101 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
102 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
103 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
105 extern const char *ReleaseDate;
106 extern size_t UngetCount;
108 static void set_xterm_title_bar (char *title)
110 fputs ("\033]2;", stdout);
111 fputs (title, stdout);
112 fputs ("\007", stdout);
116 static void set_xterm_icon_name (char *name)
118 fputs ("\033]1;", stdout);
119 fputs (name, stdout);
120 fputs ("\007", stdout);
124 void index_make_entry (char *s, size_t l, MUTTMENU * menu, int num)
127 M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
128 int edgemsgno, reverse = Sort & SORT_REVERSE;
129 HEADER *h = Context->hdrs[Context->v2r[num]];
132 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
133 flag |= M_FORMAT_TREE; /* display the thread tree */
134 if (h->display_subject)
135 flag |= M_FORMAT_FORCESUBJ;
138 if (menu->top + menu->pagelen > menu->max)
139 edgemsgno = Context->v2r[menu->max - 1];
141 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
144 edgemsgno = Context->v2r[menu->top];
146 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
150 /* if no ancestor is visible on current screen, provisionally force
152 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
154 flag |= M_FORMAT_FORCESUBJ;
157 else if (tmp->message->virtual >= 0)
160 if (flag & M_FORMAT_FORCESUBJ) {
161 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
165 /* ...but if a previous sibling is available, don't force it */
166 if (reverse ? tmp->message->msgno >
167 edgemsgno : tmp->message->msgno < edgemsgno)
169 else if (tmp->message->virtual >= 0) {
170 flag &= ~M_FORMAT_FORCESUBJ;
178 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
181 int index_color (int index_no)
183 HEADER *h = Context->hdrs[Context->v2r[index_no]];
188 mutt_set_header_color (Context, h);
192 static int ci_next_undeleted (int msgno)
196 for (i = msgno + 1; i < Context->vcount; i++)
197 if (!Context->hdrs[Context->v2r[i]]->deleted)
202 static int ci_previous_undeleted (int msgno)
206 for (i = msgno - 1; i >= 0; i--)
207 if (!Context->hdrs[Context->v2r[i]]->deleted)
212 /* Return the index of the first new message, or failing that, the first
215 static int ci_first_message (void)
219 if (Context && Context->msgcount) {
220 for (i = 0; i < Context->vcount; i++) {
221 if (!Context->hdrs[Context->v2r[i]]->read &&
222 !Context->hdrs[Context->v2r[i]]->deleted) {
223 if (!Context->hdrs[Context->v2r[i]]->old)
232 /* If Sort is reverse and not threaded, the latest message is first.
233 * If Sort is threaded, the latest message is first iff exactly one
234 * of Sort and SortAux are reverse.
236 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
237 ((Sort & SORT_MASK) == SORT_THREADS &&
238 ((Sort ^ SortAux) & SORT_REVERSE)))
241 return (Context->vcount ? Context->vcount - 1 : 0);
246 /* This should be in mx.c, but it only gets used here. */
247 static int mx_toggle_write (CONTEXT * ctx)
253 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
258 if (ctx->dontwrite) {
260 mutt_message (_("Changes to folder will be written on folder exit."));
264 mutt_message (_("Changes to folder will not be written."));
270 static void update_index (MUTTMENU * menu, CONTEXT * ctx, int check,
271 int oldcount, int index_hint)
273 /* store pointers to the newly added messages */
274 HEADER **save_new = NULL;
277 /* take note of the current message */
279 if (menu->current < Context->vcount)
280 menu->oldcurrent = index_hint;
282 oldcount = 0; /* invalid message number! */
285 /* We are in a limited view. Check if the new message(s) satisfy
286 * the limit criteria. If they do, set their virtual msgno so that
287 * they will be visible in the limited view */
288 if (Context->pattern) {
289 #define THIS_BODY Context->hdrs[j]->content
290 if (oldcount || check == M_REOPENED) {
291 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount;
293 if (mutt_pattern_exec
294 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
296 Context->hdrs[j]->virtual = Context->vcount;
297 Context->v2r[Context->vcount] = j;
298 Context->hdrs[j]->limited = 1;
301 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
308 /* save the list of new messages */
309 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
311 (HEADER **) safe_malloc (sizeof (HEADER *) *
312 (Context->msgcount - oldcount));
313 for (j = oldcount; j < Context->msgcount; j++)
314 save_new[j - oldcount] = Context->hdrs[j];
317 /* if the mailbox was reopened, need to rethread from scratch */
318 mutt_sort_headers (Context, (check == M_REOPENED));
320 /* uncollapse threads with new mail */
321 if ((Sort & SORT_MASK) == SORT_THREADS) {
322 if (check == M_REOPENED) {
325 Context->collapsed = 0;
327 for (h = Context->tree; h; h = h->next) {
328 for (j = h; !j->message; j = j->child);
329 mutt_uncollapse_thread (Context, j->message);
331 mutt_set_virtual (Context);
334 for (j = 0; j < Context->msgcount - oldcount; j++) {
337 for (k = 0; k < Context->msgcount; k++) {
338 HEADER *h = Context->hdrs[k];
340 if (h == save_new[j] && (!Context->pattern || h->limited))
341 mutt_uncollapse_thread (Context, h);
345 mutt_set_virtual (Context);
351 /* restore the current message to the message it was pointing to */
352 for (j = 0; j < Context->vcount; j++) {
353 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
360 if (menu->current < 0)
361 menu->current = ci_first_message ();
365 static void resort_index (MUTTMENU * menu)
368 HEADER *current = CURHDR;
371 mutt_sort_headers (Context, 0);
372 /* Restore the current message */
374 for (i = 0; i < Context->vcount; i++) {
375 if (Context->hdrs[Context->v2r[i]] == current) {
381 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
382 menu->current = mutt_parent_message (Context, current);
384 if (menu->current < 0)
385 menu->current = ci_first_message ();
387 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
390 struct mapping_t IndexHelp[] = {
391 {N_("Quit"), OP_QUIT},
392 {N_("Del"), OP_DELETE},
393 {N_("Undel"), OP_UNDELETE},
394 {N_("Save"), OP_SAVE},
395 {N_("Mail"), OP_MAIL},
396 {N_("Reply"), OP_REPLY},
397 {N_("Group"), OP_GROUP_REPLY},
398 {N_("Help"), OP_HELP},
403 struct mapping_t IndexNewsHelp[] = {
404 {N_("Quit"), OP_QUIT},
405 {N_("Del"), OP_DELETE},
406 {N_("Undel"), OP_UNDELETE},
407 {N_("Save"), OP_SAVE},
408 {N_("Post"), OP_POST},
409 {N_("Followup"), OP_FOLLOWUP},
410 {N_("Catchup"), OP_CATCHUP},
411 {N_("Help"), OP_HELP},
416 /* This function handles the message index window as well as commands returned
417 * from the pager (MENU_PAGER).
419 int mutt_index_menu (void)
421 char buf[LONG_STRING], helpstr[SHORT_STRING];
424 int done = 0; /* controls when to exit the "event" loop */
426 int tag = 0; /* has the tag-prefix command been pressed? */
431 char *cp; /* temporary variable. */
432 int index_hint; /* used to restore cursor position */
433 int do_buffy_notify = 1;
434 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
435 int attach_msg = option (OPTATTACHMSG);
437 menu = mutt_new_menu ();
438 menu->menu = MENU_MAIN;
440 menu->pagelen = LINES - 3;
441 menu->make_entry = index_make_entry;
442 menu->color = index_color;
443 menu->current = ci_first_message ();
444 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
447 && (Context->magic ==
448 M_NNTP)) ? IndexNewsHelp :
453 mutt_buffy_check (1); /* force the buffy check after we enter the folder */
454 /* record folder we open to place sidebar indicator properly */
455 if (Context && Context->path)
456 set_curbuffy (Context->path);
460 tag = 0; /* clear the tag-prefix */
462 menu->max = Context ? Context->vcount : 0;
463 oldcount = Context ? Context->msgcount : 0;
465 /* check if we need to resort the index because just about
466 * any 'op' below could do mutt_enter_command(), either here or
467 * from any new menu launched, and change $sort/$sort_aux
469 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
472 if (option (OPTREDRAWTREE) && Context && Context->msgcount
473 && (Sort & SORT_MASK) == SORT_THREADS) {
474 mutt_draw_tree (Context);
475 menu->redraw |= REDRAW_STATUS;
476 unset_option (OPTREDRAWTREE);
479 if (Context && !attach_msg) {
482 /* check for new mail in the mailbox. If nonzero, then something has
483 * changed about the file (either we got new mail or the file was
484 * modified underneath us.)
488 imap_allow_reopen (Context);
491 index_hint = (Context->vcount && menu->current >= 0
492 && menu->current < Context->vcount) ? CURHDR->index : 0;
494 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
495 if (!Context->path) {
496 /* fatal error occurred */
498 menu->redraw = REDRAW_FULL;
500 set_option (OPTSEARCHINVALID);
502 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
503 update_index (menu, Context, check, oldcount, index_hint);
505 /* notify the user of new mail */
506 if (check == M_REOPENED)
508 ("Mailbox was externally modified. Flags may be wrong."));
509 else if (check == M_NEW_MAIL) {
510 /* on new mail: redraw sidebar */
511 draw_sidebar (CurrentMenu);
512 mutt_message (_("New mail in this mailbox."));
514 if (option (OPTBEEPNEW))
517 else if (check == M_FLAGS)
518 mutt_message (_("Mailbox was externally modified."));
520 /* avoid the message being overwritten by buffy */
523 menu->redraw = REDRAW_FULL;
524 menu->max = Context->vcount;
526 set_option (OPTSEARCHINVALID);
532 imap_disallow_reopen (Context);
536 /* check for new mail in the incoming folders */
538 if ((newcount = mutt_buffy_check (0)) != oldcount) {
539 menu->redraw |= REDRAW_STATUS;
540 menu->redraw |= REDRAW_SIDEBAR;
542 if (do_buffy_notify) {
543 if (mutt_buffy_notify () && option (OPTBEEPNEW))
552 if (menu->redraw & REDRAW_SIDEBAR)
553 draw_sidebar (menu->menu);
554 if (menu->redraw & REDRAW_FULL) {
555 menu_redraw_full (menu);
556 draw_sidebar (menu->menu);
560 if (menu->menu == MENU_MAIN) {
561 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
562 menu_check_recenter (menu);
564 if (menu->redraw & REDRAW_INDEX) {
565 menu_redraw_index (menu);
566 menu->redraw |= REDRAW_STATUS;
568 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
569 menu_redraw_motion (menu);
570 else if (menu->redraw & REDRAW_CURRENT)
571 menu_redraw_current (menu);
574 if (menu->redraw & REDRAW_STATUS) {
576 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
578 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
579 SETCOLOR (MT_COLOR_STATUS);
580 mutt_paddstr (COLS, buf);
581 SETCOLOR (MT_COLOR_NORMAL);
582 set_buffystats (Context);
583 menu->redraw &= ~REDRAW_STATUS;
584 if (option (OPTXTERMSETTITLES)) {
585 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
586 set_xterm_title_bar (buf);
587 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
588 set_xterm_icon_name (buf);
593 if (menu->current < menu->max)
594 menu->oldcurrent = menu->current;
596 menu->oldcurrent = -1;
598 if (option (OPTARROWCURSOR))
599 move (menu->current - menu->top + menu->offset, 2);
601 move (menu->current - menu->top + menu->offset, COLS - 1);
604 op = km_dokey (MENU_MAIN);
607 (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op));
609 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
612 mutt_resize_screen ();
613 menu->redraw = REDRAW_FULL;
614 menu->menu = MENU_MAIN;
616 menu->top = 0; /* so we scroll the right amount */
618 * force a real complete redraw. clrtobot() doesn't seem to be able
619 * to handle every case without this.
621 clearok (stdscr, TRUE);
627 continue; /* either user abort or timeout */
631 /* special handling for the tag-prefix function */
632 if (op == OP_TAG_PREFIX) {
634 mutt_error (_("No mailbox is open."));
639 if (!Context->tagged) {
640 mutt_error (_("No tagged messages."));
646 /* give visual indication that the next command is a tag- command */
647 mvaddstr (LINES - 1, 0, "tag-");
650 /* get the real command */
651 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
652 /* abort tag sequence */
653 CLEARLINE (LINES - 1);
657 else if (option (OPTAUTOTAG) && Context && Context->tagged)
660 if (op == OP_TAG_PREFIX_COND) {
662 mutt_error (_("No mailbox is open."));
667 if (!Context->tagged) {
670 while (UngetCount > 0) {
672 if (tmp.op == OP_END_COND)
675 mutt_message (_("Nothing to do."));
681 /* give visual indication that the next command is a tag- command */
682 mvaddstr (LINES - 1, 0, "tag-");
685 /* get the real command */
686 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
687 /* abort tag sequence */
688 CLEARLINE (LINES - 1);
696 if (menu->current < menu->max)
697 menu->oldcurrent = menu->current;
699 menu->oldcurrent = -1;
701 mutt_curs_set (1); /* fallback from the pager */
705 unset_option (OPTNEWS); /* for any case */
710 /* ----------------------------------------------------------------------
715 menu_bottom_page (menu);
718 menu_first_entry (menu);
721 menu_middle_page (menu);
727 menu_half_down (menu);
730 menu_next_line (menu);
733 menu_prev_line (menu);
736 menu_next_page (menu);
739 menu_prev_page (menu);
742 menu_last_entry (menu);
745 menu_top_page (menu);
748 menu_current_top (menu);
750 case OP_CURRENT_MIDDLE:
751 menu_current_middle (menu);
753 case OP_CURRENT_BOTTOM:
754 menu_current_bottom (menu);
761 if (Context->magic == M_NNTP) {
764 if (op == OP_GET_MESSAGE) {
766 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0)
771 LIST *ref = CURHDR->env->references;
774 mutt_error (_("Article has no parent reference!"));
778 strfcpy (buf, ref->data, sizeof (buf));
780 if (!Context->id_hash)
781 Context->id_hash = mutt_make_id_hash (Context);
782 if ((h = hash_find (Context->id_hash, buf))) {
783 if (h->virtual != -1) {
784 menu->current = h->virtual;
785 menu->redraw = REDRAW_MOTION_RESYNCH;
787 else if (h->collapsed) {
788 mutt_uncollapse_thread (Context, h);
789 mutt_set_virtual (Context);
790 menu->current = h->virtual;
791 menu->redraw = REDRAW_MOTION_RESYNCH;
794 mutt_error (_("Message not visible in limited view."));
797 if (nntp_check_msgid (Context, buf) == 0) {
798 h = Context->hdrs[Context->msgcount - 1];
799 mutt_sort_headers (Context, 0);
800 menu->current = h->virtual;
801 menu->redraw = REDRAW_FULL;
804 mutt_error (_("Article %s not found on server"), buf);
809 case OP_GET_CHILDREN:
810 case OP_RECONSTRUCT_THREAD:
812 if (Context->magic == M_NNTP) {
814 int old = CURHDR->index, i;
816 if (!CURHDR->env->message_id) {
817 mutt_error (_("No Message-Id. Unable to perform operation"));
822 if (!Context->id_hash)
823 Context->id_hash = mutt_make_id_hash (Context);
824 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
826 if (op == OP_RECONSTRUCT_THREAD) {
827 LIST *ref = CURHDR->env->references;
830 nntp_check_msgid (Context, ref->data);
831 /* the last msgid in References is the root message */
833 strfcpy (buf, ref->data, sizeof (buf));
837 mutt_message (_("Check for children of message..."));
839 if (nntp_check_children (Context, buf) == 0) {
840 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
841 h = hash_find (Context->id_hash, buf);
842 /* if the root message was retrieved, move to it */
844 menu->current = h->virtual;
845 else /* try to restore old position */
846 for (i = 0; i < Context->msgcount; i++)
847 if (Context->hdrs[i]->index == old) {
848 menu->current = Context->hdrs[i]->virtual;
849 /* As an added courtesy, recenter the menu
850 * with the current entry at the middle of the screen */
851 menu_check_recenter (menu);
852 menu_current_middle (menu);
855 menu->redraw = REDRAW_FULL;
865 if (isdigit (LastKey))
866 mutt_ungetch (LastKey, 0);
868 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
872 if (!isdigit ((unsigned char) buf[0])) {
873 mutt_error (_("Argument must be a message number."));
879 if (i > 0 && i <= Context->msgcount) {
880 for (j = i - 1; j < Context->msgcount; j++) {
881 if (Context->hdrs[j]->virtual != -1)
884 if (j >= Context->msgcount) {
885 for (j = i - 2; j >= 0; j--) {
886 if (Context->hdrs[j]->virtual != -1)
892 menu->current = Context->hdrs[j]->virtual;
893 if (menu->menu == MENU_PAGER) {
894 op = OP_DISPLAY_MESSAGE;
898 menu->redraw = REDRAW_MOTION;
901 mutt_error (_("That message is not visible."));
904 mutt_error (_("Invalid message number."));
908 /* --------------------------------------------------------------------
909 * `index' specific commands
912 case OP_MAIN_DELETE_PATTERN:
919 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
923 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
924 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
928 case OP_MAIN_FETCH_MAIL:
932 menu->redraw = REDRAW_FULL;
938 mutt_help (MENU_MAIN);
939 menu->redraw = REDRAW_FULL;
942 case OP_MAIN_SHOW_LIMIT:
944 if (!Context->pattern)
945 mutt_message (_("No limit pattern is in effect."));
950 /* i18n: ask for a limit to apply */
951 snprintf (buf, sizeof (buf), _("Limit: %s"), Context->pattern);
952 mutt_message ("%s", buf);
960 menu->oldcurrent = (Context->vcount && menu->current >= 0
962 Context->vcount) ? CURHDR->index : -1;
963 if (op == OP_TOGGLE_READ) {
964 char buf[LONG_STRING];
966 if (!Context->pattern
967 || strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
968 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
969 Context->pattern ? Context->pattern : ".*");
970 set_option (OPTHIDEREAD);
973 strfcpy (buf, Context->pattern + 8, sizeof (buf));
974 if (!*buf || strncmp (buf, ".*", 2) == 0)
975 snprintf (buf, sizeof (buf), "~A");
976 unset_option (OPTHIDEREAD);
978 FREE (&Context->pattern);
979 Context->pattern = safe_strdup (buf);
981 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
982 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
984 if (menu->oldcurrent >= 0) {
985 /* try to find what used to be the current message */
987 for (i = 0; i < Context->vcount; i++)
988 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
992 if (menu->current < 0)
997 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
998 if ((Sort & SORT_MASK) == SORT_THREADS)
999 mutt_draw_tree (Context);
1000 menu->redraw = REDRAW_FULL;
1012 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES) {
1015 oldcount = Context ? Context->msgcount : 0;
1018 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1021 if (check == M_NEW_MAIL || check == M_REOPENED)
1022 update_index (menu, Context, check, oldcount, index_hint);
1024 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1025 set_option (OPTSEARCHINVALID);
1032 clearok (stdscr, TRUE);
1033 menu->redraw = REDRAW_FULL;
1037 case OP_SEARCH_REVERSE:
1038 case OP_SEARCH_NEXT:
1039 case OP_SEARCH_OPPOSITE:
1043 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1044 menu->current = menu->oldcurrent;
1046 menu->redraw = REDRAW_MOTION;
1050 case OP_SORT_REVERSE:
1052 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1053 if (Context && Context->msgcount) {
1054 resort_index (menu);
1055 set_option (OPTSEARCHINVALID);
1064 if (tag && !option (OPTAUTOTAG)) {
1065 for (j = 0; j < Context->vcount; j++)
1066 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1067 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1070 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1071 Context->last_tag = CURHDR->tagged ? CURHDR :
1072 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1073 ? NULL : Context->last_tag);
1074 menu->redraw = REDRAW_STATUS;
1075 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1077 menu->redraw |= REDRAW_MOTION_RESYNCH;
1080 menu->redraw |= REDRAW_CURRENT;
1084 case OP_MAIN_TAG_PATTERN:
1088 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1089 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1092 case OP_MAIN_UNDELETE_PATTERN:
1099 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1102 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1104 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1107 case OP_MAIN_UNTAG_PATTERN:
1111 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1112 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1115 /* --------------------------------------------------------------------
1116 * The following operations can be performed inside of the pager.
1120 case OP_MAIN_IMAP_FETCH:
1121 if (Context->magic == M_IMAP)
1122 imap_check_mailbox (Context, &index_hint, 1);
1126 case OP_MAIN_SYNC_FOLDER:
1128 if (Context && !Context->msgcount)
1135 int oldvcount = Context->vcount;
1136 int oldcount = Context->msgcount;
1140 /* calculate the number of messages _above_ the cursor,
1141 * so we can keep the cursor on the current message
1143 for (j = 0; j <= menu->current; j++) {
1144 if (Context->hdrs[Context->v2r[j]]->deleted)
1148 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1149 if (Context->vcount != oldvcount)
1150 menu->current -= dcount;
1151 set_option (OPTSEARCHINVALID);
1153 else if (check == M_NEW_MAIL || check == M_REOPENED)
1154 update_index (menu, Context, check, oldcount, index_hint);
1157 * do a sanity check even if mx_sync_mailbox failed.
1160 if (menu->current < 0 || menu->current >= Context->vcount)
1161 menu->current = ci_first_message ();
1164 /* check for a fatal error, or all messages deleted */
1168 /* if we were in the pager, redisplay the message */
1169 if (menu->menu == MENU_PAGER) {
1170 op = OP_DISPLAY_MESSAGE;
1174 menu->redraw = REDRAW_FULL;
1177 case OP_SIDEBAR_OPEN:
1178 case OP_MAIN_CHANGE_FOLDER:
1179 case OP_MAIN_CHANGE_FOLDER_READONLY:
1181 case OP_MAIN_CHANGE_GROUP:
1182 case OP_MAIN_CHANGE_GROUP_READONLY:
1184 if (attach_msg || option (OPTREADONLY) ||
1186 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1188 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1194 cp = _("Open mailbox in read-only mode");
1196 cp = _("Open mailbox");
1200 unset_option (OPTNEWS);
1201 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1202 set_option (OPTNEWS);
1203 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1206 cp = _("Open newsgroup in read-only mode");
1208 cp = _("Open newsgroup");
1214 if (Context && Context->path)
1215 strncpy (buf, Context->path, sizeof (buf));
1216 mutt_buffy (buf, sizeof (buf));
1219 if (op == OP_SIDEBAR_OPEN) {
1222 strncpy (buf, CurBuffy->path, sizeof (buf));
1224 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) ==
1228 CLEARLINE (LINES - 1);
1233 if (option (OPTNEWS)) {
1234 unset_option (OPTNEWS);
1235 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1239 mutt_expand_path (buf, sizeof (buf));
1241 if (mx_get_magic (buf) <= 0) {
1242 mutt_error (_("%s is not a mailbox."), buf);
1245 mutt_str_replace (&CurrentFolder, buf);
1250 #ifdef USE_COMPRESSED
1251 if (Context->compressinfo && Context->realpath)
1252 mutt_str_replace (&LastFolder, Context->realpath);
1256 mutt_str_replace (&LastFolder, Context->path);
1257 oldcount = Context ? Context->msgcount : 0;
1259 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1260 if (check == M_NEW_MAIL || check == M_REOPENED)
1261 update_index (menu, Context, check, oldcount, index_hint);
1263 set_option (OPTSEARCHINVALID);
1264 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1272 /* Set CurrentMenu to MENU_MAIN before executing any folder
1273 * hooks so that all the index menu functions are available to
1277 CurrentMenu = MENU_MAIN;
1278 mutt_folder_hook (buf);
1280 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1281 menu->current = ci_first_message ();
1287 /* mutt_buffy_check() must be done with mail-reader mode! */
1288 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1290 && (Context->magic ==
1291 M_NNTP)) ? IndexNewsHelp :
1294 mutt_clear_error ();
1295 mutt_buffy_check (1); /* force the buffy check after we have changed
1297 menu->redraw = REDRAW_FULL;
1298 set_option (OPTSEARCHINVALID);
1301 case OP_DISPLAY_MESSAGE:
1302 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1307 * toggle the weeding of headers so that a user can press the key
1308 * again while reading the message.
1310 if (op == OP_DISPLAY_HEADERS)
1311 toggle_option (OPTWEED);
1313 unset_option (OPTNEEDRESORT);
1315 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1316 mutt_uncollapse_thread (Context, CURHDR);
1317 mutt_set_virtual (Context);
1318 if (option (OPTUNCOLLAPSEJUMP))
1319 menu->current = mutt_thread_next_unread (Context, CURHDR);
1322 if ((op = mutt_display_message (CURHDR)) == -1) {
1323 unset_option (OPTNEEDRESORT);
1327 menu->menu = MENU_PAGER;
1328 menu->oldcurrent = menu->current;
1334 if (menu->menu == MENU_MAIN && attach_msg) {
1339 if ((menu->menu == MENU_MAIN)
1340 && (query_quadoption (OPT_QUIT,
1341 _("Exit Mutt-ng without saving?")) == M_YES))
1344 mx_fastclose_mailbox (Context);
1356 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1357 /* if we were in the pager, redisplay the message */
1358 if (menu->menu == MENU_PAGER) {
1359 op = OP_DISPLAY_MESSAGE;
1363 menu->redraw = REDRAW_CURRENT;
1366 case OP_MAIN_BREAK_THREAD:
1372 if ((Sort & SORT_MASK) != SORT_THREADS)
1373 mutt_error (_("Threading is not enabled."));
1377 HEADER *oldcur = CURHDR;
1379 mutt_break_thread (CURHDR);
1380 mutt_sort_headers (Context, 1);
1381 menu->current = oldcur->virtual;
1384 Context->changed = 1;
1385 mutt_message _("Thread broken");
1387 if (menu->menu == MENU_PAGER) {
1388 op = OP_DISPLAY_MESSAGE;
1392 menu->redraw |= REDRAW_INDEX;
1396 case OP_MAIN_LINK_THREADS:
1402 if ((Sort & SORT_MASK) != SORT_THREADS)
1403 mutt_error (_("Threading is not enabled."));
1405 else if (!CURHDR->env->message_id)
1406 mutt_error (_("No Message-ID: header available to link thread"));
1408 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1409 mutt_error (_("First, please tag a message to be linked here"));
1412 HEADER *oldcur = CURHDR;
1414 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1416 mutt_sort_headers (Context, 1);
1417 menu->current = oldcur->virtual;
1419 Context->changed = 1;
1420 mutt_message _("Threads linked");
1423 mutt_error (_("No thread linked"));
1426 if (menu->menu == MENU_PAGER) {
1427 op = OP_DISPLAY_MESSAGE;
1431 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1434 case OP_MAIN_NEXT_UNDELETED:
1438 if (menu->current >= Context->vcount - 1) {
1439 if (menu->menu == MENU_MAIN)
1440 mutt_error (_("You are on the last message."));
1444 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1445 menu->current = menu->oldcurrent;
1446 if (menu->menu == MENU_MAIN)
1447 mutt_error (_("No undeleted messages."));
1449 else if (menu->menu == MENU_PAGER) {
1450 op = OP_DISPLAY_MESSAGE;
1454 menu->redraw = REDRAW_MOTION;
1461 if (menu->current >= Context->vcount - 1) {
1462 if (menu->menu == MENU_MAIN)
1463 mutt_error (_("You are on the last message."));
1468 if (menu->menu == MENU_PAGER) {
1469 op = OP_DISPLAY_MESSAGE;
1473 menu->redraw = REDRAW_MOTION;
1476 case OP_MAIN_PREV_UNDELETED:
1480 if (menu->current < 1) {
1481 mutt_error (_("You are on the first message."));
1485 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1486 menu->current = menu->oldcurrent;
1487 if (menu->menu == MENU_MAIN)
1488 mutt_error (_("No undeleted messages."));
1490 else if (menu->menu == MENU_PAGER) {
1491 op = OP_DISPLAY_MESSAGE;
1495 menu->redraw = REDRAW_MOTION;
1502 if (menu->current < 1) {
1503 if (menu->menu == MENU_MAIN)
1504 mutt_error (_("You are on the first message."));
1509 if (menu->menu == MENU_PAGER) {
1510 op = OP_DISPLAY_MESSAGE;
1514 menu->redraw = REDRAW_MOTION;
1517 case OP_DECRYPT_COPY:
1518 case OP_DECRYPT_SAVE:
1522 case OP_COPY_MESSAGE:
1524 case OP_DECODE_COPY:
1525 case OP_DECODE_SAVE:
1528 if (mutt_save_message (tag ? NULL : CURHDR,
1529 (op == OP_DECRYPT_SAVE) ||
1530 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1531 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1532 (op == OP_DECRYPT_SAVE)
1533 || (op == OP_DECRYPT_COPY)
1534 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1541 menu->redraw |= REDRAW_INDEX;
1542 else if (option (OPTRESOLVE)) {
1543 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1544 menu->current = menu->oldcurrent;
1545 menu->redraw |= REDRAW_CURRENT;
1548 menu->redraw |= REDRAW_MOTION_RESYNCH;
1551 menu->redraw |= REDRAW_CURRENT;
1555 case OP_MAIN_NEXT_NEW:
1556 case OP_MAIN_NEXT_UNREAD:
1557 case OP_MAIN_PREV_NEW:
1558 case OP_MAIN_PREV_UNREAD:
1559 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1560 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1563 int first_unread = -1;
1571 for (j = 0; j != Context->vcount; j++) {
1572 #define CURHDRi Context->hdrs[Context->v2r[i]]
1573 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1574 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1576 if (i > Context->vcount - 1) {
1577 mutt_message _("Search wrapped to top.");
1585 mutt_message _("Search wrapped to bottom.");
1587 i = Context->vcount - 1;
1591 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1592 if (UNREAD (CURHDRi) && first_unread == -1)
1594 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1597 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1598 if (first_unread == -1)
1600 if ((!CURHDRi->old) && first_new == -1)
1604 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1607 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1608 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1609 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1614 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1615 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1616 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1618 menu->current = first_new;
1619 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1620 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1621 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1622 && first_unread != -1)
1623 menu->current = first_unread;
1625 if (menu->current == -1) {
1626 menu->current = menu->oldcurrent;
1627 mutt_error ("%s%s.",
1628 (op == OP_MAIN_NEXT_NEW
1630 OP_MAIN_PREV_NEW) ? _("No new messages") :
1631 _("No unread messages"),
1632 Context->pattern ? _(" in this limited view") : "");
1634 else if (menu->menu == MENU_PAGER) {
1635 op = OP_DISPLAY_MESSAGE;
1639 menu->redraw = REDRAW_MOTION;
1642 case OP_FLAG_MESSAGE:
1649 if (Context->magic == M_POP) {
1651 mutt_error (_("Can't change 'important' flag on POP server."));
1658 CHECK_IMAP_ACL (IMAP_ACL_WRITE);
1662 if (Context->magic == M_NNTP) {
1664 mutt_error (_("Can't change 'important' flag on NNTP server."));
1671 for (j = 0; j < Context->vcount; j++) {
1672 if (Context->hdrs[Context->v2r[j]]->tagged)
1673 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1674 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1677 menu->redraw |= REDRAW_INDEX;
1680 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1681 if (option (OPTRESOLVE)) {
1682 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1683 menu->current = menu->oldcurrent;
1684 menu->redraw = REDRAW_CURRENT;
1687 menu->redraw = REDRAW_MOTION_RESYNCH;
1690 menu->redraw = REDRAW_CURRENT;
1692 menu->redraw |= REDRAW_STATUS;
1702 CHECK_IMAP_ACL (IMAP_ACL_SEEN);
1706 for (j = 0; j < Context->vcount; j++) {
1707 if (Context->hdrs[Context->v2r[j]]->tagged) {
1708 if (Context->hdrs[Context->v2r[j]]->read ||
1709 Context->hdrs[Context->v2r[j]]->old)
1710 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1713 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1717 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1720 if (CURHDR->read || CURHDR->old)
1721 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1723 mutt_set_flag (Context, CURHDR, M_READ, 1);
1725 if (option (OPTRESOLVE)) {
1726 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1727 menu->current = menu->oldcurrent;
1728 menu->redraw = REDRAW_CURRENT;
1731 menu->redraw = REDRAW_MOTION_RESYNCH;
1734 menu->redraw = REDRAW_CURRENT;
1735 menu->redraw |= REDRAW_STATUS;
1739 case OP_TOGGLE_WRITE:
1742 if (mx_toggle_write (Context) == 0)
1743 menu->redraw |= REDRAW_STATUS;
1746 case OP_MAIN_NEXT_THREAD:
1747 case OP_MAIN_NEXT_SUBTHREAD:
1748 case OP_MAIN_PREV_THREAD:
1749 case OP_MAIN_PREV_SUBTHREAD:
1754 case OP_MAIN_NEXT_THREAD:
1755 menu->current = mutt_next_thread (CURHDR);
1758 case OP_MAIN_NEXT_SUBTHREAD:
1759 menu->current = mutt_next_subthread (CURHDR);
1762 case OP_MAIN_PREV_THREAD:
1763 menu->current = mutt_previous_thread (CURHDR);
1766 case OP_MAIN_PREV_SUBTHREAD:
1767 menu->current = mutt_previous_subthread (CURHDR);
1771 if (menu->current < 0) {
1772 menu->current = menu->oldcurrent;
1773 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1774 mutt_error (_("No more threads."));
1777 mutt_error (_("You are on the first thread."));
1779 else if (menu->menu == MENU_PAGER) {
1780 op = OP_DISPLAY_MESSAGE;
1784 menu->redraw = REDRAW_MOTION;
1787 case OP_MAIN_PARENT_MESSAGE:
1792 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1793 menu->current = menu->oldcurrent;
1795 else if (menu->menu == MENU_PAGER) {
1796 op = OP_DISPLAY_MESSAGE;
1800 menu->redraw = REDRAW_MOTION;
1803 case OP_MAIN_SET_FLAG:
1804 case OP_MAIN_CLEAR_FLAG:
1811 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1814 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
1816 menu->redraw = REDRAW_STATUS;
1818 menu->redraw |= REDRAW_INDEX;
1819 else if (option (OPTRESOLVE)) {
1820 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1821 menu->current = menu->oldcurrent;
1822 menu->redraw |= REDRAW_CURRENT;
1825 menu->redraw |= REDRAW_MOTION_RESYNCH;
1828 menu->redraw |= REDRAW_CURRENT;
1832 case OP_MAIN_COLLAPSE_THREAD:
1836 if ((Sort & SORT_MASK) != SORT_THREADS) {
1837 mutt_error (_("Threading is not enabled."));
1842 if (CURHDR->collapsed) {
1843 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1844 mutt_set_virtual (Context);
1845 if (option (OPTUNCOLLAPSEJUMP))
1846 menu->current = mutt_thread_next_unread (Context, CURHDR);
1848 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1849 menu->current = mutt_collapse_thread (Context, CURHDR);
1850 mutt_set_virtual (Context);
1853 mutt_error (_("Thread contains unread messages."));
1858 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1862 case OP_MAIN_COLLAPSE_ALL:
1866 if ((Sort & SORT_MASK) != SORT_THREADS) {
1867 mutt_error (_("Threading is not enabled."));
1874 THREAD *thread, *top;
1877 if (CURHDR->collapsed)
1878 final = mutt_uncollapse_thread (Context, CURHDR);
1879 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1880 final = mutt_collapse_thread (Context, CURHDR);
1882 final = CURHDR->virtual;
1884 base = Context->hdrs[Context->v2r[final]];
1886 top = Context->tree;
1887 Context->collapsed = !Context->collapsed;
1888 while ((thread = top) != NULL) {
1889 while (!thread->message)
1890 thread = thread->child;
1891 h = thread->message;
1893 if (h->collapsed != Context->collapsed) {
1895 mutt_uncollapse_thread (Context, h);
1896 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1897 mutt_collapse_thread (Context, h);
1902 mutt_set_virtual (Context);
1903 for (j = 0; j < Context->vcount; j++) {
1904 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1910 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1914 /* --------------------------------------------------------------------
1915 * These functions are invoked directly from the internal-pager
1918 case OP_BOUNCE_MESSAGE:
1923 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1926 case OP_CREATE_ALIAS:
1928 mutt_create_alias (Context
1929 && Context->vcount ? CURHDR->env : NULL, NULL);
1930 MAYBE_REDRAW (menu->redraw);
1931 menu->redraw |= REDRAW_CURRENT;
1936 mutt_query_menu (NULL, 0);
1937 MAYBE_REDRAW (menu->redraw);
1940 case OP_PURGE_MESSAGE:
1948 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1952 mutt_tag_set_flag (M_DELETE, 1);
1953 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1954 if (option (OPTDELETEUNTAG))
1955 mutt_tag_set_flag (M_TAG, 0);
1956 menu->redraw = REDRAW_INDEX;
1959 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1960 mutt_set_flag (Context, CURHDR, M_PURGED,
1961 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1962 if (option (OPTDELETEUNTAG))
1963 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1964 if (option (OPTRESOLVE)) {
1965 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1966 menu->current = menu->oldcurrent;
1967 menu->redraw = REDRAW_CURRENT;
1969 else if (menu->menu == MENU_PAGER) {
1970 op = OP_DISPLAY_MESSAGE;
1974 menu->redraw |= REDRAW_MOTION_RESYNCH;
1977 menu->redraw = REDRAW_CURRENT;
1979 menu->redraw |= REDRAW_STATUS;
1982 case OP_DELETE_THREAD:
1983 case OP_DELETE_SUBTHREAD:
1990 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
1993 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1994 op == OP_DELETE_THREAD ? 0 : 1);
1997 if (option (OPTDELETEUNTAG))
1998 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1999 op == OP_DELETE_THREAD ? 0 : 1);
2000 if (option (OPTRESOLVE))
2001 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
2002 menu->current = menu->oldcurrent;
2003 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2009 if (Context && Context->magic == M_NNTP) {
2010 if (mutt_newsgroup_catchup (CurrentNewsSrv,
2011 ((NNTP_DATA *) Context->data)->group))
2012 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2017 case OP_DISPLAY_ADDRESS:
2021 mutt_display_address (CURHDR->env);
2024 case OP_ENTER_COMMAND:
2026 CurrentMenu = MENU_MAIN;
2027 mutt_enter_command ();
2028 mutt_check_rescore (Context);
2029 if (option (OPTFORCEREDRAWINDEX))
2030 menu->redraw = REDRAW_FULL;
2031 unset_option (OPTFORCEREDRAWINDEX);
2032 unset_option (OPTFORCEREDRAWPAGER);
2035 case OP_EDIT_MESSAGE:
2043 if (Context->magic == M_POP) {
2045 mutt_error (_("Can't edit message on POP server."));
2052 CHECK_IMAP_ACL (IMAP_ACL_INSERT);
2056 if (Context->magic == M_NNTP) {
2058 mutt_error (_("Can't edit message on newsserver."));
2064 if (option (OPTPGPAUTODEC)
2065 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2066 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2067 mutt_edit_message (Context, tag ? NULL : CURHDR);
2068 menu->redraw = REDRAW_FULL;
2072 case OP_FORWARD_MESSAGE:
2077 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2078 menu->redraw = REDRAW_FULL;
2082 case OP_FORGET_PASSPHRASE:
2083 crypt_forget_passphrase ();
2086 case OP_GROUP_REPLY:
2091 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2092 tag ? NULL : CURHDR);
2093 menu->redraw = REDRAW_FULL;
2101 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2102 tag ? NULL : CURHDR);
2103 menu->redraw = REDRAW_FULL;
2109 ci_send_message (0, NULL, NULL, Context, NULL);
2110 menu->redraw = REDRAW_FULL;
2114 if (!(WithCrypto & APPLICATION_PGP))
2117 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2118 menu->redraw = REDRAW_FULL;
2122 case OP_EXTRACT_KEYS:
2127 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2128 menu->redraw = REDRAW_FULL;
2132 case OP_CHECK_TRADITIONAL:
2133 if (!(WithCrypto & APPLICATION_PGP))
2137 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2138 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2140 if (menu->menu == MENU_PAGER) {
2141 op = OP_DISPLAY_MESSAGE;
2150 mutt_pipe_message (tag ? NULL : CURHDR);
2151 MAYBE_REDRAW (menu->redraw);
2158 mutt_print_message (tag ? NULL : CURHDR);
2161 case OP_MAIN_READ_THREAD:
2162 case OP_MAIN_READ_SUBTHREAD:
2169 CHECK_IMAP_ACL (IMAP_ACL_SEEN);
2172 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2173 op == OP_MAIN_READ_THREAD ? 0 : 1);
2176 if (option (OPTRESOLVE)) {
2177 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2178 mutt_next_thread (CURHDR) :
2179 mutt_next_subthread (CURHDR))) == -1)
2180 menu->current = menu->oldcurrent;
2182 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2186 case OP_RECALL_MESSAGE:
2189 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2190 menu->redraw = REDRAW_FULL;
2200 for (j = 0; j < Context->vcount; j++) {
2201 if (Context->hdrs[Context->v2r[j]]->tagged)
2202 mutt_resend_message (NULL, Context,
2203 Context->hdrs[Context->v2r[j]]);
2207 mutt_resend_message (NULL, Context, CURHDR);
2209 menu->redraw = REDRAW_FULL;
2215 case OP_FORWARD_TO_GROUP:
2218 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2219 Context && Context->msgcount == 0) {
2220 mutt_error (_("There are no messages."));
2223 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2224 mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2225 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2226 _("Reply by mail as poster prefers?")) !=
2228 if (Context && Context->magic == M_NNTP
2229 && !((NNTP_DATA *) Context->data)->allowed
2230 && query_quadoption (OPT_TOMODERATED,
2232 ("Posting to this group not allowed, may be moderated. Continue?"))
2236 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2239 if (op == OP_FOLLOWUP)
2240 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2241 tag ? NULL : CURHDR);
2243 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2244 tag ? NULL : CURHDR);
2246 menu->redraw = REDRAW_FULL;
2256 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2257 menu->redraw = REDRAW_FULL;
2260 case OP_SHELL_ESCAPE:
2262 mutt_shell_escape ();
2263 MAYBE_REDRAW (menu->redraw);
2267 case OP_TAG_SUBTHREAD:
2271 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2272 op == OP_TAG_THREAD ? 0 : 1);
2275 if (option (OPTRESOLVE)) {
2276 menu->current = mutt_next_thread (CURHDR);
2278 if (menu->current == -1)
2279 menu->current = menu->oldcurrent;
2281 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2292 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2296 mutt_tag_set_flag (M_DELETE, 0);
2297 mutt_tag_set_flag (M_PURGED, 0);
2298 menu->redraw = REDRAW_INDEX;
2301 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2302 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2303 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2305 menu->redraw = REDRAW_MOTION_RESYNCH;
2308 menu->redraw = REDRAW_CURRENT;
2310 menu->redraw |= REDRAW_STATUS;
2313 case OP_UNDELETE_THREAD:
2314 case OP_UNDELETE_SUBTHREAD:
2321 CHECK_IMAP_ACL (IMAP_ACL_DELETE);
2324 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2325 op == OP_UNDELETE_THREAD ? 0 : 1)
2326 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2327 op == OP_UNDELETE_THREAD ? 0 : 1);
2330 if (option (OPTRESOLVE)) {
2331 if (op == OP_UNDELETE_THREAD)
2332 menu->current = mutt_next_thread (CURHDR);
2334 menu->current = mutt_next_subthread (CURHDR);
2336 if (menu->current == -1)
2337 menu->current = menu->oldcurrent;
2339 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2349 menu->redraw = REDRAW_FULL;
2352 case OP_VIEW_ATTACHMENTS:
2355 mutt_view_attachments (CURHDR);
2356 if (CURHDR->attach_del)
2357 Context->changed = 1;
2358 menu->redraw = REDRAW_FULL;
2368 case OP_SIDEBAR_SCROLL_UP:
2369 case OP_SIDEBAR_SCROLL_DOWN:
2370 case OP_SIDEBAR_NEXT:
2371 case OP_SIDEBAR_PREV:
2372 case OP_SIDEBAR_NEXT_NEW:
2373 case OP_SIDEBAR_PREV_NEW:
2374 scroll_sidebar (op, menu->menu);
2377 if (menu->menu == MENU_MAIN)
2378 km_error_key (MENU_MAIN);
2381 if (menu->menu == MENU_PAGER) {
2382 menu->menu = MENU_MAIN;
2383 menu->redraw = REDRAW_FULL;
2385 set_option (OPTWEED); /* turn header weeding back on. */
2394 /* Close all open IMAP connections */
2399 /* Close all open NNTP connections */
2404 mutt_menuDestroy (&menu);
2408 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2415 for (color = ColorIndexList; color; color = color->next)
2416 if (mutt_pattern_exec
2417 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2418 curhdr->pair = color->pair;
2421 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];