2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 #include "mutt_curses.h"
26 #include "mutt_menu.h"
39 #include "imap_private.h"
42 #include "mutt_crypt.h"
57 static const char *No_mailbox_is_open = N_("No mailbox is open.");
58 static const char *There_are_no_messages = N_("There are no messages.");
59 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
60 static const char *Function_not_permitted_in_attach_message_mode = N_("Function not permitted in attach-message mode.");
61 static const char *No_visible = N_("No visible messages.");
63 #define CHECK_MSGCOUNT if (!Context) \
66 mutt_error _(No_mailbox_is_open); \
69 else if (!Context->msgcount) \
72 mutt_error _(There_are_no_messages); \
76 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
79 mutt_error _(No_visible); \
84 #define CHECK_READONLY if (Context->readonly) \
87 mutt_error _(Mailbox_is_read_only); \
92 /* the error message returned here could be better. */
93 #define CHECK_IMAP_ACL(aclbit) if (Context->magic == M_IMAP) \
94 if (mutt_bit_isset (((IMAP_DATA *)Context->data)->capabilities, ACL) \
95 && !mutt_bit_isset(((IMAP_DATA *)Context->data)->rights,aclbit)){ \
97 mutt_error ("Operation not permitted by the IMAP ACL for this mailbox"); \
102 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
105 mutt_error _(Function_not_permitted_in_attach_message_mode); \
109 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
110 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
111 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
113 extern const char *ReleaseDate;
114 extern size_t UngetCount;
116 static void set_xterm_title_bar(char *title)
118 fputs("\033]2;", stdout);
119 fputs(title, stdout);
120 fputs("\007", stdout);
124 static void set_xterm_icon_name(char *name)
126 fputs("\033]1;", stdout);
128 fputs("\007", stdout);
132 void index_make_entry (char *s, size_t l, MUTTMENU *menu, int num)
134 format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
135 int edgemsgno, reverse = Sort & SORT_REVERSE;
136 HEADER *h = Context->hdrs[Context->v2r[num]];
139 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree)
141 flag |= M_FORMAT_TREE; /* display the thread tree */
142 if (h->display_subject)
143 flag |= M_FORMAT_FORCESUBJ;
148 if (menu->top + menu->pagelen > menu->max)
149 edgemsgno = Context->v2r[menu->max - 1];
151 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
154 edgemsgno = Context->v2r[menu->top];
156 for (tmp = h->thread->parent; tmp; tmp = tmp->parent)
161 /* if no ancestor is visible on current screen, provisionally force
163 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno < edgemsgno)
165 flag |= M_FORMAT_FORCESUBJ;
168 else if (tmp->message->virtual >= 0)
171 if (flag & M_FORMAT_FORCESUBJ)
173 for (tmp = h->thread->prev; tmp; tmp = tmp->prev)
178 /* ...but if a previous sibling is available, don't force it */
179 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno < edgemsgno)
181 else if (tmp->message->virtual >= 0)
183 flag &= ~M_FORMAT_FORCESUBJ;
191 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
194 int index_color (int index_no)
196 HEADER *h = Context->hdrs[Context->v2r[index_no]];
201 mutt_set_header_color (Context, h);
205 static int ci_next_undeleted (int msgno)
209 for (i=msgno+1; i < Context->vcount; i++)
210 if (! Context->hdrs[Context->v2r[i]]->deleted)
215 static int ci_previous_undeleted (int msgno)
219 for (i=msgno-1; i>=0; i--)
220 if (! Context->hdrs[Context->v2r[i]]->deleted)
225 /* Return the index of the first new message, or failing that, the first
228 static int ci_first_message (void)
232 if (Context && Context->msgcount)
234 for (i=0; i < Context->vcount; i++)
236 if (! Context->hdrs[Context->v2r[i]]->read &&
237 ! Context->hdrs[Context->v2r[i]]->deleted)
239 if (! Context->hdrs[Context->v2r[i]]->old)
248 /* If Sort is reverse and not threaded, the latest message is first.
249 * If Sort is threaded, the latest message is first iff exactly one
250 * of Sort and SortAux are reverse.
252 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
253 ((Sort & SORT_MASK) == SORT_THREADS &&
254 ((Sort ^ SortAux) & SORT_REVERSE)))
257 return (Context->vcount ? Context->vcount - 1 : 0);
262 /* This should be in mx.c, but it only gets used here. */
263 static int mx_toggle_write (CONTEXT *ctx)
270 mutt_error _("Cannot toggle write on a readonly mailbox!");
277 mutt_message _("Changes to folder will be written on folder exit.");
282 mutt_message _("Changes to folder will not be written.");
288 static void update_index (MUTTMENU *menu, CONTEXT *ctx, int check,
289 int oldcount, int index_hint)
291 /* store pointers to the newly added messages */
292 HEADER **save_new = NULL;
295 /* take note of the current message */
298 if (menu->current < Context->vcount)
299 menu->oldcurrent = index_hint;
301 oldcount = 0; /* invalid message number! */
304 /* We are in a limited view. Check if the new message(s) satisfy
305 * the limit criteria. If they do, set their virtual msgno so that
306 * they will be visible in the limited view */
307 if (Context->pattern)
309 #define THIS_BODY Context->hdrs[j]->content
310 if (oldcount || check == M_REOPENED)
312 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++)
314 if (mutt_pattern_exec (Context->limit_pattern,
315 M_MATCH_FULL_ADDRESS,
316 Context, Context->hdrs[j]))
318 Context->hdrs[j]->virtual = Context->vcount;
319 Context->v2r[Context->vcount] = j;
320 Context->hdrs[j]->limited = 1;
322 Context->vsize += THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
329 /* save the list of new messages */
330 if (oldcount && check != M_REOPENED
331 && ((Sort & SORT_MASK) == SORT_THREADS))
333 save_new = (HEADER **) safe_malloc (sizeof (HEADER *) * (Context->msgcount - oldcount));
334 for (j = oldcount; j < Context->msgcount; j++)
335 save_new[j-oldcount] = Context->hdrs[j];
338 /* if the mailbox was reopened, need to rethread from scratch */
339 mutt_sort_headers (Context, (check == M_REOPENED));
341 /* uncollapse threads with new mail */
342 if ((Sort & SORT_MASK) == SORT_THREADS)
344 if (check == M_REOPENED)
348 Context->collapsed = 0;
350 for (h = Context->tree; h; h = h->next)
352 for (j = h; !j->message; j = j->child)
354 mutt_uncollapse_thread (Context, j->message);
356 mutt_set_virtual (Context);
360 for (j = 0; j < Context->msgcount - oldcount; j++)
364 for (k = 0; k < Context->msgcount; k++)
366 HEADER *h = Context->hdrs[k];
367 if (h == save_new[j] && (!Context->pattern || h->limited))
368 mutt_uncollapse_thread (Context, h);
372 mutt_set_virtual (Context);
379 /* restore the current message to the message it was pointing to */
380 for (j = 0; j < Context->vcount; j++)
382 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent)
390 if (menu->current < 0)
391 menu->current = ci_first_message ();
395 static void resort_index (MUTTMENU *menu)
398 HEADER *current = CURHDR;
401 mutt_sort_headers (Context, 0);
402 /* Restore the current message */
404 for (i = 0; i < Context->vcount; i++)
406 if (Context->hdrs[Context->v2r[i]] == current)
413 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
414 menu->current = mutt_parent_message (Context, current);
416 if (menu->current < 0)
417 menu->current = ci_first_message ();
419 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
422 struct mapping_t IndexHelp[] = {
423 { N_("Quit"), OP_QUIT },
424 { N_("Del"), OP_DELETE },
425 { N_("Undel"), OP_UNDELETE },
426 { N_("Save"), OP_SAVE },
427 { N_("Mail"), OP_MAIL },
428 { N_("Reply"), OP_REPLY },
429 { N_("Group"), OP_GROUP_REPLY },
430 { N_("Help"), OP_HELP },
435 struct mapping_t IndexNewsHelp[] = {
436 { N_("Quit"), OP_QUIT },
437 { N_("Del"), OP_DELETE },
438 { N_("Undel"), OP_UNDELETE },
439 { N_("Save"), OP_SAVE },
440 { N_("Post"), OP_POST },
441 { N_("Followup"), OP_FOLLOWUP },
442 { N_("Catchup"), OP_CATCHUP },
443 { N_("Help"), OP_HELP },
448 /* This function handles the message index window as well as commands returned
449 * from the pager (MENU_PAGER).
451 int mutt_index_menu (void)
453 char buf[LONG_STRING], helpstr[SHORT_STRING];
456 int done = 0; /* controls when to exit the "event" loop */
458 int tag = 0; /* has the tag-prefix command been pressed? */
463 char *cp; /* temporary variable. */
464 int index_hint; /* used to restore cursor position */
465 int do_buffy_notify = 1;
466 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
467 int attach_msg = option(OPTATTACHMSG);
469 menu = mutt_new_menu ();
470 menu->menu = MENU_MAIN;
472 menu->pagelen = LINES - 3;
473 menu->make_entry = index_make_entry;
474 menu->color = index_color;
475 menu->current = ci_first_message ();
476 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
478 (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp :
483 mutt_buffy_check(1); /* force the buffy check after we enter the folder */
487 tag = 0; /* clear the tag-prefix */
489 menu->max = Context ? Context->vcount : 0;
490 oldcount = Context ? Context->msgcount : 0;
492 /* check if we need to resort the index because just about
493 * any 'op' below could do mutt_enter_command(), either here or
494 * from any new menu launched, and change $sort/$sort_aux
496 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
499 if (option (OPTREDRAWTREE) && Context && Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
501 mutt_draw_tree (Context);
502 menu->redraw |= REDRAW_STATUS;
503 unset_option (OPTREDRAWTREE);
506 if (Context && !attach_msg)
509 /* check for new mail in the mailbox. If nonzero, then something has
510 * changed about the file (either we got new mail or the file was
511 * modified underneath us.)
515 imap_allow_reopen (Context);
518 index_hint = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ? CURHDR->index : 0;
520 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0)
524 /* fatal error occurred */
526 menu->redraw = REDRAW_FULL;
529 set_option (OPTSEARCHINVALID);
531 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS)
533 update_index (menu, Context, check, oldcount, index_hint);
535 /* notify the user of new mail */
536 if (check == M_REOPENED)
537 mutt_error _("Mailbox was externally modified. Flags may be wrong.");
538 else if (check == M_NEW_MAIL)
540 mutt_message _("New mail in this mailbox.");
541 if (option (OPTBEEPNEW))
543 } else if (check == M_FLAGS)
544 mutt_message _("Mailbox was externally modified.");
546 /* avoid the message being overwritten by buffy */
549 menu->redraw = REDRAW_FULL;
550 menu->max = Context->vcount;
552 set_option (OPTSEARCHINVALID);
558 imap_disallow_reopen (Context);
563 /* check for new mail in the incoming folders */
565 if ((newcount = mutt_buffy_check (0)) != oldcount)
566 menu->redraw |= REDRAW_STATUS;
569 if (mutt_buffy_notify () && option (OPTBEEPNEW))
579 if (menu->redraw & REDRAW_FULL)
581 menu_redraw_full (menu);
582 draw_sidebar(menu->menu);
586 if (menu->menu == MENU_MAIN)
588 if (Context && Context->hdrs && !(menu->current >= Context->vcount))
590 menu_check_recenter (menu);
592 if (menu->redraw & REDRAW_INDEX)
594 menu_redraw_index (menu);
595 menu->redraw |= REDRAW_STATUS;
597 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
598 menu_redraw_motion (menu);
599 else if (menu->redraw & REDRAW_CURRENT)
600 menu_redraw_current (menu);
603 if (menu->redraw & REDRAW_STATUS)
606 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
608 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
609 SETCOLOR (MT_COLOR_STATUS);
610 mutt_paddstr (COLS, buf);
611 SETCOLOR (MT_COLOR_NORMAL);
612 set_buffystats (Context);
613 menu->redraw &= ~REDRAW_STATUS;
614 if (option(OPTXTERMSETTITLES))
616 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
617 set_xterm_title_bar(buf);
618 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
619 set_xterm_icon_name(buf);
624 if (menu->current < menu->max)
625 menu->oldcurrent = menu->current;
627 menu->oldcurrent = -1;
629 if (option (OPTARROWCURSOR))
630 move (menu->current - menu->top + menu->offset, 2);
632 move (menu->current - menu->top + menu->offset, COLS - 1);
635 op = km_dokey (MENU_MAIN);
637 dprint(4, (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op));
639 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
643 mutt_resize_screen ();
644 menu->redraw = REDRAW_FULL;
645 menu->menu = MENU_MAIN;
647 menu->top = 0; /* so we scroll the right amount */
649 * force a real complete redraw. clrtobot() doesn't seem to be able
650 * to handle every case without this.
652 clearok(stdscr,TRUE);
658 continue; /* either user abort or timeout */
662 /* special handling for the tag-prefix function */
663 if (op == OP_TAG_PREFIX)
667 mutt_error _("No mailbox is open.");
671 if (!Context->tagged)
673 mutt_error _("No tagged messages.");
678 /* give visual indication that the next command is a tag- command */
679 mvaddstr (LINES - 1, 0, "tag-");
682 /* get the real command */
683 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX)
685 /* abort tag sequence */
690 else if (option (OPTAUTOTAG) && Context && Context->tagged)
693 if (op == OP_TAG_PREFIX_COND)
697 mutt_error _("No mailbox is open.");
701 if (!Context->tagged)
707 if(tmp.op==OP_END_COND)break;
709 mutt_message _("Nothing to do.");
714 /* give visual indication that the next command is a tag- command */
715 mvaddstr (LINES - 1, 0, "tag-");
718 /* get the real command */
719 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX)
721 /* abort tag sequence */
731 if (menu->current < menu->max)
732 menu->oldcurrent = menu->current;
734 menu->oldcurrent = -1;
736 mutt_curs_set (1); /* fallback from the pager */
740 unset_option (OPTNEWS); /* for any case */
746 /* ----------------------------------------------------------------------
751 menu_bottom_page (menu);
754 menu_first_entry (menu);
757 menu_middle_page (menu);
763 menu_half_down (menu);
766 menu_next_line (menu);
769 menu_prev_line (menu);
772 menu_next_page (menu);
775 menu_prev_page (menu);
778 menu_last_entry (menu);
781 menu_top_page (menu);
784 menu_current_top (menu);
786 case OP_CURRENT_MIDDLE:
787 menu_current_middle (menu);
789 case OP_CURRENT_BOTTOM:
790 menu_current_bottom (menu);
797 if (Context->magic == M_NNTP)
801 if (op == OP_GET_MESSAGE)
804 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0) != 0
810 LIST *ref = CURHDR->env->references;
813 mutt_error _("Article has no parent reference!");
816 strfcpy (buf, ref->data, sizeof (buf));
818 if (!Context->id_hash)
819 Context->id_hash = mutt_make_id_hash (Context);
820 if ((h = hash_find (Context->id_hash, buf)))
822 if (h->virtual != -1)
824 menu->current = h->virtual;
825 menu->redraw = REDRAW_MOTION_RESYNCH;
827 else if (h->collapsed)
829 mutt_uncollapse_thread (Context, h);
830 mutt_set_virtual (Context);
831 menu->current = h->virtual;
832 menu->redraw = REDRAW_MOTION_RESYNCH;
835 mutt_error _("Message not visible in limited view.");
839 if (nntp_check_msgid (Context, buf) == 0)
841 h = Context->hdrs[Context->msgcount-1];
842 mutt_sort_headers (Context, 0);
843 menu->current = h->virtual;
844 menu->redraw = REDRAW_FULL;
847 mutt_error (_("Article %s not found on server"), buf);
852 case OP_GET_CHILDREN:
853 case OP_RECONSTRUCT_THREAD:
855 if (Context->magic == M_NNTP)
858 int old = CURHDR->index, i;
860 if (!CURHDR->env->message_id)
862 mutt_error _("No Message-Id. Unable to perform operation");
866 if (!Context->id_hash)
867 Context->id_hash = mutt_make_id_hash (Context);
868 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
870 if (op == OP_RECONSTRUCT_THREAD)
872 LIST *ref = CURHDR->env->references;
875 nntp_check_msgid (Context, ref->data);
876 /* the last msgid in References is the root message */
878 strfcpy (buf, ref->data, sizeof (buf));
882 mutt_message _("Check for children of message...");
883 if (nntp_check_children (Context, buf) == 0)
885 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
886 h = hash_find (Context->id_hash, buf);
887 /* if the root message was retrieved, move to it */
889 menu->current = h->virtual;
890 else /* try to restore old position */
891 for (i = 0; i < Context->msgcount; i++)
892 if (Context->hdrs[i]->index == old)
894 menu->current = Context->hdrs[i]->virtual;
895 /* As an added courtesy, recenter the menu
896 * with the current entry at the middle of the screen */
897 menu_check_recenter (menu);
898 menu_current_middle (menu);
901 menu->redraw = REDRAW_FULL;
911 if (isdigit (LastKey)) mutt_ungetch (LastKey, 0);
913 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
917 if (! isdigit ((unsigned char) buf[0]))
919 mutt_error _("Argument must be a message number.");
924 if (i > 0 && i <= Context->msgcount)
926 for (j = i-1; j < Context->msgcount; j++)
928 if (Context->hdrs[j]->virtual != -1)
931 if (j >= Context->msgcount)
933 for (j = i-2; j >= 0; j--)
935 if (Context->hdrs[j]->virtual != -1)
942 menu->current = Context->hdrs[j]->virtual;
943 if (menu->menu == MENU_PAGER)
945 op = OP_DISPLAY_MESSAGE;
949 menu->redraw = REDRAW_MOTION;
952 mutt_error _("That message is not visible.");
955 mutt_error _("Invalid message number.");
959 /* --------------------------------------------------------------------
960 * `index' specific commands
963 case OP_MAIN_DELETE_PATTERN:
970 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
974 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
975 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
979 case OP_MAIN_FETCH_MAIL:
983 menu->redraw = REDRAW_FULL;
989 mutt_help (MENU_MAIN);
990 menu->redraw = REDRAW_FULL;
993 case OP_MAIN_SHOW_LIMIT:
995 if (!Context->pattern)
996 mutt_message _("No limit pattern is in effect.");
1000 /* i18n: ask for a limit to apply */
1001 snprintf (buf, sizeof(buf), _("Limit: %s"),Context->pattern);
1002 mutt_message ("%s", buf);
1007 case OP_TOGGLE_READ:
1010 menu->oldcurrent = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ?
1012 if (op == OP_TOGGLE_READ)
1014 char buf[LONG_STRING];
1016 if (!Context->pattern || strncmp (Context->pattern, "!~R!~D~s", 8) != 0)
1018 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
1019 Context->pattern ? Context->pattern : ".*");
1020 set_option (OPTHIDEREAD);
1024 strfcpy (buf, Context->pattern + 8, sizeof(buf));
1025 if (!*buf || strncmp (buf, ".*", 2) == 0)
1026 snprintf (buf, sizeof(buf), "~A");
1027 unset_option (OPTHIDEREAD);
1029 FREE (&Context->pattern);
1030 Context->pattern = safe_strdup (buf);
1032 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
1033 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
1035 if (menu->oldcurrent >= 0)
1037 /* try to find what used to be the current message */
1039 for (i = 0; i < Context->vcount; i++)
1040 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent)
1045 if (menu->current < 0) menu->current = 0;
1049 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1050 if ((Sort & SORT_MASK) == SORT_THREADS)
1051 mutt_draw_tree (Context);
1052 menu->redraw = REDRAW_FULL;
1065 if (query_quadoption (OPT_QUIT, _("Quit Mutt?")) == M_YES)
1069 oldcount = Context ? Context->msgcount : 0;
1071 if (!Context || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1075 if (check == M_NEW_MAIL || check == M_REOPENED)
1076 update_index (menu, Context, check, oldcount, index_hint);
1078 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1079 set_option (OPTSEARCHINVALID);
1086 clearok (stdscr, TRUE);
1087 menu->redraw = REDRAW_FULL;
1091 case OP_SEARCH_REVERSE:
1092 case OP_SEARCH_NEXT:
1093 case OP_SEARCH_OPPOSITE:
1097 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1098 menu->current = menu->oldcurrent;
1100 menu->redraw = REDRAW_MOTION;
1104 case OP_SORT_REVERSE:
1106 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0)
1108 if (Context && Context->msgcount)
1110 resort_index (menu);
1111 set_option (OPTSEARCHINVALID);
1120 if (tag && !option (OPTAUTOTAG))
1122 for (j = 0; j < Context->vcount; j++)
1123 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1124 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1128 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1129 Context->last_tag = CURHDR->tagged ? CURHDR :
1130 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1131 ? NULL : Context->last_tag);
1132 menu->redraw = REDRAW_STATUS;
1133 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1)
1136 menu->redraw |= REDRAW_MOTION_RESYNCH;
1139 menu->redraw |= REDRAW_CURRENT;
1143 case OP_MAIN_TAG_PATTERN:
1147 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1148 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1151 case OP_MAIN_UNDELETE_PATTERN:
1158 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
1161 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) == 0)
1162 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1165 case OP_MAIN_UNTAG_PATTERN:
1169 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1170 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1173 /* --------------------------------------------------------------------
1174 * The following operations can be performed inside of the pager.
1178 case OP_MAIN_IMAP_FETCH:
1179 if (Context->magic == M_IMAP)
1180 imap_check_mailbox (Context, &index_hint, 1);
1184 case OP_MAIN_SYNC_FOLDER:
1186 if (Context && !Context->msgcount)
1193 int oldvcount = Context->vcount;
1194 int oldcount = Context->msgcount;
1198 /* calculate the number of messages _above_ the cursor,
1199 * so we can keep the cursor on the current message
1201 for (j = 0; j <= menu->current; j++)
1203 if (Context->hdrs[Context->v2r[j]]->deleted)
1207 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0)
1209 if (Context->vcount != oldvcount)
1210 menu->current -= dcount;
1211 set_option (OPTSEARCHINVALID);
1213 else if (check == M_NEW_MAIL || check == M_REOPENED)
1214 update_index (menu, Context, check, oldcount, index_hint);
1217 * do a sanity check even if mx_sync_mailbox failed.
1220 if (menu->current < 0 || menu->current >= Context->vcount)
1221 menu->current = ci_first_message ();
1224 /* check for a fatal error, or all messages deleted */
1228 /* if we were in the pager, redisplay the message */
1229 if (menu->menu == MENU_PAGER)
1231 op = OP_DISPLAY_MESSAGE;
1235 menu->redraw = REDRAW_FULL;
1238 case OP_SIDEBAR_OPEN:
1239 case OP_MAIN_CHANGE_FOLDER:
1240 case OP_MAIN_CHANGE_FOLDER_READONLY:
1242 case OP_MAIN_CHANGE_GROUP:
1243 case OP_MAIN_CHANGE_GROUP_READONLY:
1245 if (attach_msg || option (OPTREADONLY) ||
1247 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1249 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1255 cp = _("Open mailbox in read-only mode");
1257 cp = _("Open mailbox");
1261 unset_option (OPTNEWS);
1262 if (op == OP_MAIN_CHANGE_GROUP ||
1263 op == OP_MAIN_CHANGE_GROUP_READONLY)
1265 set_option (OPTNEWS);
1266 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1269 cp = _("Open newsgroup in read-only mode");
1271 cp = _("Open newsgroup");
1276 mutt_buffy (buf, sizeof (buf));
1278 if ( op == OP_SIDEBAR_OPEN ) {
1281 strncpy( buf, CurBuffy->path, sizeof(buf) );
1282 } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
1286 CLEARLINE (LINES-1);
1291 if (option (OPTNEWS))
1293 unset_option (OPTNEWS);
1294 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1298 mutt_expand_path (buf, sizeof (buf));
1300 if (mx_get_magic (buf) <= 0)
1302 mutt_error (_("%s is not a mailbox."), buf);
1310 #ifdef USE_COMPRESSED
1311 if (Context->compressinfo && Context->realpath)
1312 mutt_str_replace (&LastFolder, Context->realpath);
1316 mutt_str_replace (&LastFolder, Context->path);
1317 oldcount = Context ? Context->msgcount : 0;
1319 if ((check = mx_close_mailbox (Context, &index_hint)) != 0)
1321 if (check == M_NEW_MAIL || check == M_REOPENED)
1322 update_index (menu, Context, check, oldcount, index_hint);
1324 set_option (OPTSEARCHINVALID);
1325 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1333 /* Set CurrentMenu to MENU_MAIN before executing any folder
1334 * hooks so that all the index menu functions are available to
1338 CurrentMenu = MENU_MAIN;
1339 mutt_folder_hook (buf);
1341 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL)
1343 menu->current = ci_first_message ();
1349 /* mutt_buffy_check() must be done with mail-reader mode! */
1350 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1351 (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp : IndexHelp);
1353 mutt_clear_error ();
1354 mutt_buffy_check(1); /* force the buffy check after we have changed
1356 menu->redraw = REDRAW_FULL;
1357 set_option (OPTSEARCHINVALID);
1360 case OP_DISPLAY_MESSAGE:
1361 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1366 * toggle the weeding of headers so that a user can press the key
1367 * again while reading the message.
1369 if (op == OP_DISPLAY_HEADERS)
1370 toggle_option (OPTWEED);
1372 unset_option (OPTNEEDRESORT);
1374 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed)
1376 mutt_uncollapse_thread (Context, CURHDR);
1377 mutt_set_virtual (Context);
1378 if (option (OPTUNCOLLAPSEJUMP))
1379 menu->current = mutt_thread_next_unread (Context, CURHDR);
1382 if ((op = mutt_display_message (CURHDR)) == -1)
1384 unset_option (OPTNEEDRESORT);
1388 menu->menu = MENU_PAGER;
1389 menu->oldcurrent = menu->current;
1395 if (menu->menu == MENU_MAIN && attach_msg)
1401 if ((menu->menu == MENU_MAIN)
1402 && (query_quadoption (OPT_QUIT,
1403 _("Exit Mutt without saving?")) == M_YES))
1407 mx_fastclose_mailbox (Context);
1419 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1420 /* if we were in the pager, redisplay the message */
1421 if (menu->menu == MENU_PAGER)
1423 op = OP_DISPLAY_MESSAGE;
1427 menu->redraw = REDRAW_CURRENT;
1430 case OP_MAIN_NEXT_UNDELETED:
1434 if (menu->current >= Context->vcount - 1)
1436 if (menu->menu == MENU_MAIN)
1437 mutt_error _("You are on the last message.");
1440 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1442 menu->current = menu->oldcurrent;
1443 if (menu->menu == MENU_MAIN)
1444 mutt_error _("No undeleted messages.");
1446 else if (menu->menu == MENU_PAGER)
1448 op = OP_DISPLAY_MESSAGE;
1452 menu->redraw = REDRAW_MOTION;
1459 if (menu->current >= Context->vcount - 1)
1461 if (menu->menu == MENU_MAIN)
1462 mutt_error _("You are on the last message.");
1466 if (menu->menu == MENU_PAGER)
1468 op = OP_DISPLAY_MESSAGE;
1472 menu->redraw = REDRAW_MOTION;
1475 case OP_MAIN_PREV_UNDELETED:
1479 if (menu->current < 1)
1481 mutt_error _("You are on the first message.");
1484 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)
1492 op = OP_DISPLAY_MESSAGE;
1496 menu->redraw = REDRAW_MOTION;
1503 if (menu->current < 1)
1505 if (menu->menu == MENU_MAIN) mutt_error _("You are on the first message.");
1509 if (menu->menu == MENU_PAGER)
1511 op = OP_DISPLAY_MESSAGE;
1515 menu->redraw = REDRAW_MOTION;
1518 case OP_DECRYPT_COPY:
1519 case OP_DECRYPT_SAVE:
1523 case OP_COPY_MESSAGE:
1525 case OP_DECODE_COPY:
1526 case OP_DECODE_SAVE:
1529 if (mutt_save_message (tag ? NULL : CURHDR,
1530 (op == OP_DECRYPT_SAVE) ||
1531 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1532 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1533 (op == OP_DECRYPT_SAVE) || (op == OP_DECRYPT_COPY) ||
1535 &menu->redraw) == 0 &&
1536 (op == OP_SAVE || op == OP_DECODE_SAVE || op == OP_DECRYPT_SAVE)
1540 menu->redraw |= REDRAW_INDEX;
1541 else if (option (OPTRESOLVE))
1543 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1545 menu->current = menu->oldcurrent;
1546 menu->redraw |= REDRAW_CURRENT;
1549 menu->redraw |= REDRAW_MOTION_RESYNCH;
1552 menu->redraw |= REDRAW_CURRENT;
1556 case OP_MAIN_NEXT_NEW:
1557 case OP_MAIN_NEXT_UNREAD:
1558 case OP_MAIN_PREV_NEW:
1559 case OP_MAIN_PREV_UNREAD:
1560 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1561 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1564 int first_unread = -1;
1572 for (j = 0; j != Context->vcount; j++)
1574 #define CURHDRi Context->hdrs[Context->v2r[i]]
1575 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_NEXT_NEW_THEN_UNREAD)
1578 if (i > Context->vcount - 1)
1580 mutt_message _("Search wrapped to top.");
1589 mutt_message _("Search wrapped to bottom.");
1590 i = Context->vcount - 1;
1594 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS)
1596 if (UNREAD (CURHDRi) && first_unread == -1)
1598 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1601 else if ((!CURHDRi->deleted && !CURHDRi->read))
1603 if (first_unread == -1)
1605 if ((!CURHDRi->old) && first_new == -1)
1609 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1612 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1613 op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1618 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1619 op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1621 menu->current = first_new;
1622 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1623 op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1624 && first_unread != -1)
1625 menu->current = first_unread;
1627 if (menu->current == -1)
1629 menu->current = menu->oldcurrent;
1630 mutt_error ("%s%s.", (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW) ? _("No new messages") : _("No unread messages"),
1631 Context->pattern ? _(" in this limited view") : "");
1633 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)
1652 mutt_error _("Can't change 'important' flag on POP server.");
1658 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1662 if (Context->magic == M_NNTP)
1665 mutt_error _("Can't change 'important' flag on NNTP server.");
1672 for (j = 0; j < Context->vcount; j++)
1674 if (Context->hdrs[Context->v2r[j]]->tagged)
1675 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1676 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1679 menu->redraw |= REDRAW_INDEX;
1683 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1684 if (option (OPTRESOLVE))
1686 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1688 menu->current = menu->oldcurrent;
1689 menu->redraw = REDRAW_CURRENT;
1692 menu->redraw = REDRAW_MOTION_RESYNCH;
1695 menu->redraw = REDRAW_CURRENT;
1697 menu->redraw |= REDRAW_STATUS;
1707 CHECK_IMAP_ACL(IMAP_ACL_SEEN);
1712 for (j = 0; j < Context->vcount; j++)
1714 if (Context->hdrs[Context->v2r[j]]->tagged)
1716 if (Context->hdrs[Context->v2r[j]]->read ||
1717 Context->hdrs[Context->v2r[j]]->old)
1718 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW, 1);
1720 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ, 1);
1723 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1727 if (CURHDR->read || CURHDR->old)
1728 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1730 mutt_set_flag (Context, CURHDR, M_READ, 1);
1732 if (option (OPTRESOLVE))
1734 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1736 menu->current = menu->oldcurrent;
1737 menu->redraw = REDRAW_CURRENT;
1740 menu->redraw = REDRAW_MOTION_RESYNCH;
1743 menu->redraw = REDRAW_CURRENT;
1744 menu->redraw |= REDRAW_STATUS;
1748 case OP_TOGGLE_WRITE:
1751 if (mx_toggle_write (Context) == 0)
1752 menu->redraw |= REDRAW_STATUS;
1755 case OP_MAIN_NEXT_THREAD:
1756 case OP_MAIN_NEXT_SUBTHREAD:
1757 case OP_MAIN_PREV_THREAD:
1758 case OP_MAIN_PREV_SUBTHREAD:
1764 case OP_MAIN_NEXT_THREAD:
1765 menu->current = mutt_next_thread (CURHDR);
1768 case OP_MAIN_NEXT_SUBTHREAD:
1769 menu->current = mutt_next_subthread (CURHDR);
1772 case OP_MAIN_PREV_THREAD:
1773 menu->current = mutt_previous_thread (CURHDR);
1776 case OP_MAIN_PREV_SUBTHREAD:
1777 menu->current = mutt_previous_subthread (CURHDR);
1781 if (menu->current < 0)
1783 menu->current = menu->oldcurrent;
1784 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1785 mutt_error _("No more threads.");
1787 mutt_error _("You are on the first thread.");
1789 else if (menu->menu == MENU_PAGER)
1791 op = OP_DISPLAY_MESSAGE;
1795 menu->redraw = REDRAW_MOTION;
1798 case OP_MAIN_PARENT_MESSAGE:
1803 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0)
1805 menu->current = menu->oldcurrent;
1807 else if (menu->menu == MENU_PAGER)
1809 op = OP_DISPLAY_MESSAGE;
1813 menu->redraw = REDRAW_MOTION;
1816 case OP_MAIN_SET_FLAG:
1817 case OP_MAIN_CLEAR_FLAG:
1824 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1827 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0)
1829 menu->redraw = REDRAW_STATUS;
1831 menu->redraw |= REDRAW_INDEX;
1832 else if (option (OPTRESOLVE))
1834 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1836 menu->current = menu->oldcurrent;
1837 menu->redraw |= REDRAW_CURRENT;
1840 menu->redraw |= REDRAW_MOTION_RESYNCH;
1843 menu->redraw |= REDRAW_CURRENT;
1847 case OP_MAIN_COLLAPSE_THREAD:
1851 if ((Sort & SORT_MASK) != SORT_THREADS)
1853 mutt_error _("Threading is not enabled.");
1857 if (CURHDR->collapsed)
1859 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1860 mutt_set_virtual (Context);
1861 if (option (OPTUNCOLLAPSEJUMP))
1862 menu->current = mutt_thread_next_unread (Context, CURHDR);
1864 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1866 menu->current = mutt_collapse_thread (Context, CURHDR);
1867 mutt_set_virtual (Context);
1871 mutt_error _("Thread contains unread messages.");
1875 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1879 case OP_MAIN_COLLAPSE_ALL:
1883 if ((Sort & SORT_MASK) != SORT_THREADS)
1885 mutt_error _("Threading is not enabled.");
1891 THREAD *thread, *top;
1894 if (CURHDR->collapsed)
1895 final = mutt_uncollapse_thread (Context, CURHDR);
1896 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1897 final = mutt_collapse_thread (Context, CURHDR);
1899 final = CURHDR->virtual;
1901 base = Context->hdrs[Context->v2r[final]];
1903 top = Context->tree;
1904 Context->collapsed = !Context->collapsed;
1905 while ((thread = top) != NULL)
1907 while (!thread->message)
1908 thread = thread->child;
1909 h = thread->message;
1911 if (h->collapsed != Context->collapsed)
1914 mutt_uncollapse_thread (Context, h);
1915 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1916 mutt_collapse_thread (Context, h);
1921 mutt_set_virtual (Context);
1922 for (j = 0; j < Context->vcount; j++)
1924 if (Context->hdrs[Context->v2r[j]]->index == base->index)
1931 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1935 /* --------------------------------------------------------------------
1936 * These functions are invoked directly from the internal-pager
1939 case OP_BOUNCE_MESSAGE:
1944 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1947 case OP_CREATE_ALIAS:
1949 mutt_create_alias (Context && Context->vcount ? CURHDR->env : NULL, NULL);
1950 MAYBE_REDRAW (menu->redraw);
1951 menu->redraw |= REDRAW_CURRENT;
1956 mutt_query_menu (NULL, 0);
1957 MAYBE_REDRAW (menu->redraw);
1960 case OP_PURGE_MESSAGE:
1968 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
1973 mutt_tag_set_flag (M_DELETE, 1);
1974 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1975 if (option (OPTDELETEUNTAG))
1976 mutt_tag_set_flag (M_TAG, 0);
1977 menu->redraw = REDRAW_INDEX;
1981 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1982 mutt_set_flag (Context, CURHDR, M_PURGED,
1983 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1984 if (option (OPTDELETEUNTAG))
1985 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1986 if (option (OPTRESOLVE))
1988 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1990 menu->current = menu->oldcurrent;
1991 menu->redraw = REDRAW_CURRENT;
1993 else if (menu->menu == MENU_PAGER)
1995 op = OP_DISPLAY_MESSAGE;
1999 menu->redraw |= REDRAW_MOTION_RESYNCH;
2002 menu->redraw = REDRAW_CURRENT;
2004 menu->redraw |= REDRAW_STATUS;
2007 case OP_DELETE_THREAD:
2008 case OP_DELETE_SUBTHREAD:
2015 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2018 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
2019 op == OP_DELETE_THREAD ? 0 : 1);
2023 if (option (OPTDELETEUNTAG))
2024 mutt_thread_set_flag (CURHDR, M_TAG, 0,
2025 op == OP_DELETE_THREAD ? 0 : 1);
2026 if (option (OPTRESOLVE))
2027 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
2028 menu->current = menu->oldcurrent;
2029 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2035 if (Context && Context->magic == M_NNTP)
2037 if (mutt_newsgroup_catchup (CurrentNewsSrv,
2038 ((NNTP_DATA *)Context->data)->group))
2039 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2044 case OP_DISPLAY_ADDRESS:
2048 mutt_display_address (CURHDR->env);
2051 case OP_ENTER_COMMAND:
2053 CurrentMenu = MENU_MAIN;
2054 mutt_enter_command ();
2055 mutt_check_rescore (Context);
2056 if (option (OPTFORCEREDRAWINDEX))
2057 menu->redraw = REDRAW_FULL;
2058 unset_option (OPTFORCEREDRAWINDEX);
2059 unset_option (OPTFORCEREDRAWPAGER);
2062 case OP_EDIT_MESSAGE:
2070 if (Context->magic == M_POP)
2073 mutt_error _("Can't edit message on POP server.");
2079 CHECK_IMAP_ACL(IMAP_ACL_INSERT);
2083 if (Context->magic == M_NNTP)
2086 mutt_error _("Can't edit message on newsserver.");
2091 if (option (OPTPGPAUTODEC) && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2092 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2093 mutt_edit_message (Context, tag ? NULL : CURHDR);
2094 menu->redraw = REDRAW_FULL;
2098 case OP_FORWARD_MESSAGE:
2103 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2104 menu->redraw = REDRAW_FULL;
2108 case OP_FORGET_PASSPHRASE:
2109 crypt_forget_passphrase ();
2112 case OP_GROUP_REPLY:
2117 ci_send_message (SENDREPLY|SENDGROUPREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2118 menu->redraw = REDRAW_FULL;
2126 ci_send_message (SENDREPLY|SENDLISTREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2127 menu->redraw = REDRAW_FULL;
2133 ci_send_message (0, NULL, NULL, Context, NULL);
2134 menu->redraw = REDRAW_FULL;
2138 if (!(WithCrypto & APPLICATION_PGP))
2141 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2142 menu->redraw = REDRAW_FULL;
2146 case OP_EXTRACT_KEYS:
2151 crypt_extract_keys_from_messages(tag ? NULL : CURHDR);
2152 menu->redraw = REDRAW_FULL;
2156 case OP_CHECK_TRADITIONAL:
2157 if (!(WithCrypto & APPLICATION_PGP))
2161 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2162 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2164 if (menu->menu == MENU_PAGER)
2166 op = OP_DISPLAY_MESSAGE;
2175 mutt_pipe_message (tag ? NULL : CURHDR);
2176 MAYBE_REDRAW (menu->redraw);
2183 mutt_print_message (tag ? NULL : CURHDR);
2186 case OP_MAIN_READ_THREAD:
2187 case OP_MAIN_READ_SUBTHREAD:
2194 CHECK_IMAP_ACL(IMAP_ACL_SEEN);
2197 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2198 op == OP_MAIN_READ_THREAD ? 0 : 1);
2202 if (option (OPTRESOLVE))
2204 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2205 mutt_next_thread (CURHDR) : mutt_next_subthread (CURHDR))) == -1)
2206 menu->current = menu->oldcurrent;
2208 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2212 case OP_RECALL_MESSAGE:
2215 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2216 menu->redraw = REDRAW_FULL;
2227 for (j = 0; j < Context->vcount; j++)
2229 if (Context->hdrs[Context->v2r[j]]->tagged)
2230 mutt_resend_message (NULL, Context, Context->hdrs[Context->v2r[j]]);
2234 mutt_resend_message (NULL, Context, CURHDR);
2236 menu->redraw = REDRAW_FULL;
2242 case OP_FORWARD_TO_GROUP:
2245 if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2246 mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2247 query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != M_YES)
2249 if (Context && Context->magic == M_NNTP &&
2250 !((NNTP_DATA *)Context->data)->allowed &&
2251 query_quadoption (OPT_TOMODERATED, _("Posting to this group not allowed, may be moderated. Continue?")) != M_YES)
2254 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2258 if (op == OP_FOLLOWUP)
2259 ci_send_message (SENDNEWS|SENDREPLY, NULL, NULL, Context,
2260 tag ? NULL : CURHDR);
2262 ci_send_message (SENDNEWS|SENDFORWARD, NULL, NULL, Context,
2263 tag ? NULL : CURHDR);
2265 menu->redraw = REDRAW_FULL;
2275 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2276 menu->redraw = REDRAW_FULL;
2279 case OP_SHELL_ESCAPE:
2281 mutt_shell_escape ();
2282 MAYBE_REDRAW (menu->redraw);
2286 case OP_TAG_SUBTHREAD:
2290 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2291 op == OP_TAG_THREAD ? 0 : 1);
2295 if (option (OPTRESOLVE))
2297 menu->current = mutt_next_thread (CURHDR);
2299 if (menu->current == -1)
2300 menu->current = menu->oldcurrent;
2302 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2313 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2318 mutt_tag_set_flag (M_DELETE, 0);
2319 mutt_tag_set_flag (M_PURGED, 0);
2320 menu->redraw = REDRAW_INDEX;
2324 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2325 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2326 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1)
2329 menu->redraw = REDRAW_MOTION_RESYNCH;
2332 menu->redraw = REDRAW_CURRENT;
2334 menu->redraw |= REDRAW_STATUS;
2337 case OP_UNDELETE_THREAD:
2338 case OP_UNDELETE_SUBTHREAD:
2345 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2348 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2349 op == OP_UNDELETE_THREAD ? 0 : 1)
2350 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2351 op == OP_UNDELETE_THREAD ? 0 : 1);
2355 if (option (OPTRESOLVE))
2357 if (op == OP_UNDELETE_THREAD)
2358 menu->current = mutt_next_thread (CURHDR);
2360 menu->current = mutt_next_subthread (CURHDR);
2362 if (menu->current == -1)
2363 menu->current = menu->oldcurrent;
2365 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2377 case OP_VIEW_ATTACHMENTS:
2380 mutt_view_attachments (CURHDR);
2381 if (CURHDR->attach_del)
2382 Context->changed = 1;
2383 menu->redraw = REDRAW_FULL;
2393 case OP_SIDEBAR_SCROLL_UP:
2394 case OP_SIDEBAR_SCROLL_DOWN:
2395 case OP_SIDEBAR_NEXT:
2396 case OP_SIDEBAR_PREV:
2397 scroll_sidebar(op, menu->menu);
2400 if (menu->menu == MENU_MAIN)
2401 km_error_key (MENU_MAIN);
2404 if (menu->menu == MENU_PAGER)
2406 menu->menu = MENU_MAIN;
2407 menu->redraw = REDRAW_FULL;
2409 set_option (OPTWEED); /* turn header weeding back on. */
2417 /* Close all open IMAP connections */
2422 /* Close all open NNTP connections */
2427 mutt_menuDestroy (&menu);
2431 void mutt_set_header_color (CONTEXT *ctx, HEADER *curhdr)
2438 for (color = ColorIndexList; color; color = color->next)
2439 if (mutt_pattern_exec (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr))
2441 curhdr->pair = color->pair;
2444 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];