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 /* on new mail: redraw sidebar */
541 draw_sidebar (CurrentMenu);
542 mutt_message _("New mail in this mailbox.");
543 if (option (OPTBEEPNEW))
545 } else if (check == M_FLAGS)
546 mutt_message _("Mailbox was externally modified.");
548 /* avoid the message being overwritten by buffy */
551 menu->redraw = REDRAW_FULL;
552 menu->max = Context->vcount;
554 set_option (OPTSEARCHINVALID);
560 imap_disallow_reopen (Context);
565 /* check for new mail in the incoming folders */
567 if ((newcount = mutt_buffy_check (0)) != oldcount){
568 menu->redraw |= REDRAW_STATUS;
569 menu->redraw |= REDRAW_SIDEBAR;
573 if (mutt_buffy_notify () && option (OPTBEEPNEW))
582 if (menu->redraw & REDRAW_SIDEBAR) draw_sidebar(menu->menu);
583 if (menu->redraw & REDRAW_FULL)
585 menu_redraw_full (menu);
586 draw_sidebar(menu->menu);
590 if (menu->menu == MENU_MAIN)
592 if (Context && Context->hdrs && !(menu->current >= Context->vcount))
594 menu_check_recenter (menu);
596 if (menu->redraw & REDRAW_INDEX)
598 menu_redraw_index (menu);
599 menu->redraw |= REDRAW_STATUS;
601 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
602 menu_redraw_motion (menu);
603 else if (menu->redraw & REDRAW_CURRENT)
604 menu_redraw_current (menu);
607 if (menu->redraw & REDRAW_STATUS)
610 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
612 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
613 SETCOLOR (MT_COLOR_STATUS);
614 mutt_paddstr (COLS, buf);
615 SETCOLOR (MT_COLOR_NORMAL);
616 set_buffystats (Context);
617 menu->redraw &= ~REDRAW_STATUS;
618 if (option(OPTXTERMSETTITLES))
620 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermTitle));
621 set_xterm_title_bar(buf);
622 menu_status_line (buf, sizeof (buf), menu, NONULL (XtermIcon));
623 set_xterm_icon_name(buf);
628 if (menu->current < menu->max)
629 menu->oldcurrent = menu->current;
631 menu->oldcurrent = -1;
633 if (option (OPTARROWCURSOR))
634 move (menu->current - menu->top + menu->offset, 2);
636 move (menu->current - menu->top + menu->offset, COLS - 1);
639 op = km_dokey (MENU_MAIN);
641 dprint(4, (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op));
643 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
647 mutt_resize_screen ();
648 menu->redraw = REDRAW_FULL;
649 menu->menu = MENU_MAIN;
651 menu->top = 0; /* so we scroll the right amount */
653 * force a real complete redraw. clrtobot() doesn't seem to be able
654 * to handle every case without this.
656 clearok(stdscr,TRUE);
662 continue; /* either user abort or timeout */
666 /* special handling for the tag-prefix function */
667 if (op == OP_TAG_PREFIX)
671 mutt_error _("No mailbox is open.");
675 if (!Context->tagged)
677 mutt_error _("No tagged messages.");
682 /* give visual indication that the next command is a tag- command */
683 mvaddstr (LINES - 1, 0, "tag-");
686 /* get the real command */
687 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX)
689 /* abort tag sequence */
694 else if (option (OPTAUTOTAG) && Context && Context->tagged)
697 if (op == OP_TAG_PREFIX_COND)
701 mutt_error _("No mailbox is open.");
705 if (!Context->tagged)
711 if(tmp.op==OP_END_COND)break;
713 mutt_message _("Nothing to do.");
718 /* give visual indication that the next command is a tag- command */
719 mvaddstr (LINES - 1, 0, "tag-");
722 /* get the real command */
723 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX)
725 /* abort tag sequence */
735 if (menu->current < menu->max)
736 menu->oldcurrent = menu->current;
738 menu->oldcurrent = -1;
740 mutt_curs_set (1); /* fallback from the pager */
744 unset_option (OPTNEWS); /* for any case */
750 /* ----------------------------------------------------------------------
755 menu_bottom_page (menu);
758 menu_first_entry (menu);
761 menu_middle_page (menu);
767 menu_half_down (menu);
770 menu_next_line (menu);
773 menu_prev_line (menu);
776 menu_next_page (menu);
779 menu_prev_page (menu);
782 menu_last_entry (menu);
785 menu_top_page (menu);
788 menu_current_top (menu);
790 case OP_CURRENT_MIDDLE:
791 menu_current_middle (menu);
793 case OP_CURRENT_BOTTOM:
794 menu_current_bottom (menu);
801 if (Context->magic == M_NNTP)
805 if (op == OP_GET_MESSAGE)
808 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0) != 0
814 LIST *ref = CURHDR->env->references;
817 mutt_error _("Article has no parent reference!");
820 strfcpy (buf, ref->data, sizeof (buf));
822 if (!Context->id_hash)
823 Context->id_hash = mutt_make_id_hash (Context);
824 if ((h = hash_find (Context->id_hash, buf)))
826 if (h->virtual != -1)
828 menu->current = h->virtual;
829 menu->redraw = REDRAW_MOTION_RESYNCH;
831 else if (h->collapsed)
833 mutt_uncollapse_thread (Context, h);
834 mutt_set_virtual (Context);
835 menu->current = h->virtual;
836 menu->redraw = REDRAW_MOTION_RESYNCH;
839 mutt_error _("Message not visible in limited view.");
843 if (nntp_check_msgid (Context, buf) == 0)
845 h = Context->hdrs[Context->msgcount-1];
846 mutt_sort_headers (Context, 0);
847 menu->current = h->virtual;
848 menu->redraw = REDRAW_FULL;
851 mutt_error (_("Article %s not found on server"), buf);
856 case OP_GET_CHILDREN:
857 case OP_RECONSTRUCT_THREAD:
859 if (Context->magic == M_NNTP)
862 int old = CURHDR->index, i;
864 if (!CURHDR->env->message_id)
866 mutt_error _("No Message-Id. Unable to perform operation");
870 if (!Context->id_hash)
871 Context->id_hash = mutt_make_id_hash (Context);
872 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
874 if (op == OP_RECONSTRUCT_THREAD)
876 LIST *ref = CURHDR->env->references;
879 nntp_check_msgid (Context, ref->data);
880 /* the last msgid in References is the root message */
882 strfcpy (buf, ref->data, sizeof (buf));
886 mutt_message _("Check for children of message...");
887 if (nntp_check_children (Context, buf) == 0)
889 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
890 h = hash_find (Context->id_hash, buf);
891 /* if the root message was retrieved, move to it */
893 menu->current = h->virtual;
894 else /* try to restore old position */
895 for (i = 0; i < Context->msgcount; i++)
896 if (Context->hdrs[i]->index == old)
898 menu->current = Context->hdrs[i]->virtual;
899 /* As an added courtesy, recenter the menu
900 * with the current entry at the middle of the screen */
901 menu_check_recenter (menu);
902 menu_current_middle (menu);
905 menu->redraw = REDRAW_FULL;
915 if (isdigit (LastKey)) mutt_ungetch (LastKey, 0);
917 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
921 if (! isdigit ((unsigned char) buf[0]))
923 mutt_error _("Argument must be a message number.");
928 if (i > 0 && i <= Context->msgcount)
930 for (j = i-1; j < Context->msgcount; j++)
932 if (Context->hdrs[j]->virtual != -1)
935 if (j >= Context->msgcount)
937 for (j = i-2; j >= 0; j--)
939 if (Context->hdrs[j]->virtual != -1)
946 menu->current = Context->hdrs[j]->virtual;
947 if (menu->menu == MENU_PAGER)
949 op = OP_DISPLAY_MESSAGE;
953 menu->redraw = REDRAW_MOTION;
956 mutt_error _("That message is not visible.");
959 mutt_error _("Invalid message number.");
963 /* --------------------------------------------------------------------
964 * `index' specific commands
967 case OP_MAIN_DELETE_PATTERN:
974 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
978 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
979 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
983 case OP_MAIN_FETCH_MAIL:
987 menu->redraw = REDRAW_FULL;
993 mutt_help (MENU_MAIN);
994 menu->redraw = REDRAW_FULL;
997 case OP_MAIN_SHOW_LIMIT:
999 if (!Context->pattern)
1000 mutt_message _("No limit pattern is in effect.");
1004 /* i18n: ask for a limit to apply */
1005 snprintf (buf, sizeof(buf), _("Limit: %s"),Context->pattern);
1006 mutt_message ("%s", buf);
1011 case OP_TOGGLE_READ:
1014 menu->oldcurrent = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ?
1016 if (op == OP_TOGGLE_READ)
1018 char buf[LONG_STRING];
1020 if (!Context->pattern || strncmp (Context->pattern, "!~R!~D~s", 8) != 0)
1022 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
1023 Context->pattern ? Context->pattern : ".*");
1024 set_option (OPTHIDEREAD);
1028 strfcpy (buf, Context->pattern + 8, sizeof(buf));
1029 if (!*buf || strncmp (buf, ".*", 2) == 0)
1030 snprintf (buf, sizeof(buf), "~A");
1031 unset_option (OPTHIDEREAD);
1033 FREE (&Context->pattern);
1034 Context->pattern = safe_strdup (buf);
1036 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
1037 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
1039 if (menu->oldcurrent >= 0)
1041 /* try to find what used to be the current message */
1043 for (i = 0; i < Context->vcount; i++)
1044 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent)
1049 if (menu->current < 0) menu->current = 0;
1053 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1054 if ((Sort & SORT_MASK) == SORT_THREADS)
1055 mutt_draw_tree (Context);
1056 menu->redraw = REDRAW_FULL;
1069 if (query_quadoption (OPT_QUIT, _("Quit Mutt-ng?")) == M_YES)
1073 oldcount = Context ? Context->msgcount : 0;
1075 if (!Context || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1079 if (check == M_NEW_MAIL || check == M_REOPENED)
1080 update_index (menu, Context, check, oldcount, index_hint);
1082 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1083 set_option (OPTSEARCHINVALID);
1090 clearok (stdscr, TRUE);
1091 menu->redraw = REDRAW_FULL;
1095 case OP_SEARCH_REVERSE:
1096 case OP_SEARCH_NEXT:
1097 case OP_SEARCH_OPPOSITE:
1101 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1102 menu->current = menu->oldcurrent;
1104 menu->redraw = REDRAW_MOTION;
1108 case OP_SORT_REVERSE:
1110 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0)
1112 if (Context && Context->msgcount)
1114 resort_index (menu);
1115 set_option (OPTSEARCHINVALID);
1124 if (tag && !option (OPTAUTOTAG))
1126 for (j = 0; j < Context->vcount; j++)
1127 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1128 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1132 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1133 Context->last_tag = CURHDR->tagged ? CURHDR :
1134 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1135 ? NULL : Context->last_tag);
1136 menu->redraw = REDRAW_STATUS;
1137 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1)
1140 menu->redraw |= REDRAW_MOTION_RESYNCH;
1143 menu->redraw |= REDRAW_CURRENT;
1147 case OP_MAIN_TAG_PATTERN:
1151 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1152 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1155 case OP_MAIN_UNDELETE_PATTERN:
1162 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
1165 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) == 0)
1166 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1169 case OP_MAIN_UNTAG_PATTERN:
1173 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1174 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1177 /* --------------------------------------------------------------------
1178 * The following operations can be performed inside of the pager.
1182 case OP_MAIN_IMAP_FETCH:
1183 if (Context->magic == M_IMAP)
1184 imap_check_mailbox (Context, &index_hint, 1);
1188 case OP_MAIN_SYNC_FOLDER:
1190 if (Context && !Context->msgcount)
1197 int oldvcount = Context->vcount;
1198 int oldcount = Context->msgcount;
1202 /* calculate the number of messages _above_ the cursor,
1203 * so we can keep the cursor on the current message
1205 for (j = 0; j <= menu->current; j++)
1207 if (Context->hdrs[Context->v2r[j]]->deleted)
1211 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0)
1213 if (Context->vcount != oldvcount)
1214 menu->current -= dcount;
1215 set_option (OPTSEARCHINVALID);
1217 else if (check == M_NEW_MAIL || check == M_REOPENED)
1218 update_index (menu, Context, check, oldcount, index_hint);
1221 * do a sanity check even if mx_sync_mailbox failed.
1224 if (menu->current < 0 || menu->current >= Context->vcount)
1225 menu->current = ci_first_message ();
1228 /* check for a fatal error, or all messages deleted */
1232 /* if we were in the pager, redisplay the message */
1233 if (menu->menu == MENU_PAGER)
1235 op = OP_DISPLAY_MESSAGE;
1239 menu->redraw = REDRAW_FULL;
1242 case OP_SIDEBAR_OPEN:
1243 case OP_MAIN_CHANGE_FOLDER:
1244 case OP_MAIN_CHANGE_FOLDER_READONLY:
1246 case OP_MAIN_CHANGE_GROUP:
1247 case OP_MAIN_CHANGE_GROUP_READONLY:
1249 if (attach_msg || option (OPTREADONLY) ||
1251 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1253 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1259 cp = _("Open mailbox in read-only mode");
1261 cp = _("Open mailbox");
1265 unset_option (OPTNEWS);
1266 if (op == OP_MAIN_CHANGE_GROUP ||
1267 op == OP_MAIN_CHANGE_GROUP_READONLY)
1269 set_option (OPTNEWS);
1270 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1273 cp = _("Open newsgroup in read-only mode");
1275 cp = _("Open newsgroup");
1281 if (Context && Context->path)
1282 strncpy (buf, Context->path, sizeof (buf));
1283 mutt_buffy (buf, sizeof (buf));
1286 if ( op == OP_SIDEBAR_OPEN ) {
1289 strncpy( buf, CurBuffy->path, sizeof(buf) );
1290 } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
1294 CLEARLINE (LINES-1);
1299 if (option (OPTNEWS))
1301 unset_option (OPTNEWS);
1302 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1306 mutt_expand_path (buf, sizeof (buf));
1308 if (mx_get_magic (buf) <= 0)
1310 mutt_error (_("%s is not a mailbox."), buf);
1313 mutt_str_replace (&CurrentFolder, buf);
1319 #ifdef USE_COMPRESSED
1320 if (Context->compressinfo && Context->realpath)
1321 mutt_str_replace (&LastFolder, Context->realpath);
1325 mutt_str_replace (&LastFolder, Context->path);
1326 oldcount = Context ? Context->msgcount : 0;
1328 if ((check = mx_close_mailbox (Context, &index_hint)) != 0)
1330 if (check == M_NEW_MAIL || check == M_REOPENED)
1331 update_index (menu, Context, check, oldcount, index_hint);
1333 set_option (OPTSEARCHINVALID);
1334 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1342 /* Set CurrentMenu to MENU_MAIN before executing any folder
1343 * hooks so that all the index menu functions are available to
1347 CurrentMenu = MENU_MAIN;
1348 mutt_folder_hook (buf);
1350 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL)
1352 menu->current = ci_first_message ();
1358 /* mutt_buffy_check() must be done with mail-reader mode! */
1359 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1360 (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp : IndexHelp);
1362 mutt_clear_error ();
1363 mutt_buffy_check(1); /* force the buffy check after we have changed
1365 menu->redraw = REDRAW_FULL;
1366 set_option (OPTSEARCHINVALID);
1369 case OP_DISPLAY_MESSAGE:
1370 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1375 * toggle the weeding of headers so that a user can press the key
1376 * again while reading the message.
1378 if (op == OP_DISPLAY_HEADERS)
1379 toggle_option (OPTWEED);
1381 unset_option (OPTNEEDRESORT);
1383 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed)
1385 mutt_uncollapse_thread (Context, CURHDR);
1386 mutt_set_virtual (Context);
1387 if (option (OPTUNCOLLAPSEJUMP))
1388 menu->current = mutt_thread_next_unread (Context, CURHDR);
1391 if ((op = mutt_display_message (CURHDR)) == -1)
1393 unset_option (OPTNEEDRESORT);
1397 menu->menu = MENU_PAGER;
1398 menu->oldcurrent = menu->current;
1404 if (menu->menu == MENU_MAIN && attach_msg)
1410 if ((menu->menu == MENU_MAIN)
1411 && (query_quadoption (OPT_QUIT,
1412 _("Exit Mutt-ng without saving?")) == M_YES))
1416 mx_fastclose_mailbox (Context);
1428 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1429 /* if we were in the pager, redisplay the message */
1430 if (menu->menu == MENU_PAGER)
1432 op = OP_DISPLAY_MESSAGE;
1436 menu->redraw = REDRAW_CURRENT;
1439 case OP_MAIN_BREAK_THREAD:
1445 if ((Sort & SORT_MASK) != SORT_THREADS)
1446 mutt_error _("Threading is not enabled.");
1450 HEADER *oldcur = CURHDR;
1452 mutt_break_thread (CURHDR);
1453 mutt_sort_headers (Context, 1);
1454 menu->current = oldcur->virtual;
1457 Context->changed = 1;
1458 mutt_message _("Thread broken");
1460 if (menu->menu == MENU_PAGER)
1462 op = OP_DISPLAY_MESSAGE;
1466 menu->redraw |= REDRAW_INDEX;
1470 case OP_MAIN_LINK_THREADS:
1476 if ((Sort & SORT_MASK) != SORT_THREADS)
1477 mutt_error _("Threading is not enabled.");
1478 else if (!CURHDR->env->message_id)
1479 mutt_error _("No Message-ID: header available to link thread");
1480 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1481 mutt_error _("First, please tag a message to be linked here");
1484 HEADER *oldcur = CURHDR;
1486 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1489 mutt_sort_headers (Context, 1);
1490 menu->current = oldcur->virtual;
1492 Context->changed = 1;
1493 mutt_message _("Threads linked");
1496 mutt_error _("No thread linked");
1499 if (menu->menu == MENU_PAGER)
1501 op = OP_DISPLAY_MESSAGE;
1505 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1508 case OP_MAIN_NEXT_UNDELETED:
1512 if (menu->current >= Context->vcount - 1)
1514 if (menu->menu == MENU_MAIN)
1515 mutt_error _("You are on the last message.");
1518 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1520 menu->current = menu->oldcurrent;
1521 if (menu->menu == MENU_MAIN)
1522 mutt_error _("No undeleted messages.");
1524 else if (menu->menu == MENU_PAGER)
1526 op = OP_DISPLAY_MESSAGE;
1530 menu->redraw = REDRAW_MOTION;
1537 if (menu->current >= Context->vcount - 1)
1539 if (menu->menu == MENU_MAIN)
1540 mutt_error _("You are on the last message.");
1544 if (menu->menu == MENU_PAGER)
1546 op = OP_DISPLAY_MESSAGE;
1550 menu->redraw = REDRAW_MOTION;
1553 case OP_MAIN_PREV_UNDELETED:
1557 if (menu->current < 1)
1559 mutt_error _("You are on the first message.");
1562 if ((menu->current = ci_previous_undeleted (menu->current)) == -1)
1564 menu->current = menu->oldcurrent;
1565 if (menu->menu == MENU_MAIN)
1566 mutt_error _("No undeleted messages.");
1568 else if (menu->menu == MENU_PAGER)
1570 op = OP_DISPLAY_MESSAGE;
1574 menu->redraw = REDRAW_MOTION;
1581 if (menu->current < 1)
1583 if (menu->menu == MENU_MAIN) mutt_error _("You are on the first message.");
1587 if (menu->menu == MENU_PAGER)
1589 op = OP_DISPLAY_MESSAGE;
1593 menu->redraw = REDRAW_MOTION;
1596 case OP_DECRYPT_COPY:
1597 case OP_DECRYPT_SAVE:
1601 case OP_COPY_MESSAGE:
1603 case OP_DECODE_COPY:
1604 case OP_DECODE_SAVE:
1607 if (mutt_save_message (tag ? NULL : CURHDR,
1608 (op == OP_DECRYPT_SAVE) ||
1609 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1610 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1611 (op == OP_DECRYPT_SAVE) || (op == OP_DECRYPT_COPY) ||
1613 &menu->redraw) == 0 &&
1614 (op == OP_SAVE || op == OP_DECODE_SAVE || op == OP_DECRYPT_SAVE)
1618 menu->redraw |= REDRAW_INDEX;
1619 else if (option (OPTRESOLVE))
1621 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1623 menu->current = menu->oldcurrent;
1624 menu->redraw |= REDRAW_CURRENT;
1627 menu->redraw |= REDRAW_MOTION_RESYNCH;
1630 menu->redraw |= REDRAW_CURRENT;
1634 case OP_MAIN_NEXT_NEW:
1635 case OP_MAIN_NEXT_UNREAD:
1636 case OP_MAIN_PREV_NEW:
1637 case OP_MAIN_PREV_UNREAD:
1638 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1639 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1642 int first_unread = -1;
1650 for (j = 0; j != Context->vcount; j++)
1652 #define CURHDRi Context->hdrs[Context->v2r[i]]
1653 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_NEXT_NEW_THEN_UNREAD)
1656 if (i > Context->vcount - 1)
1658 mutt_message _("Search wrapped to top.");
1667 mutt_message _("Search wrapped to bottom.");
1668 i = Context->vcount - 1;
1672 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS)
1674 if (UNREAD (CURHDRi) && first_unread == -1)
1676 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1679 else if ((!CURHDRi->deleted && !CURHDRi->read))
1681 if (first_unread == -1)
1683 if ((!CURHDRi->old) && first_new == -1)
1687 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1690 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1691 op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1696 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1697 op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1699 menu->current = first_new;
1700 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1701 op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1702 && first_unread != -1)
1703 menu->current = first_unread;
1705 if (menu->current == -1)
1707 menu->current = menu->oldcurrent;
1708 mutt_error ("%s%s.", (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW) ? _("No new messages") : _("No unread messages"),
1709 Context->pattern ? _(" in this limited view") : "");
1711 else if (menu->menu == MENU_PAGER)
1713 op = OP_DISPLAY_MESSAGE;
1717 menu->redraw = REDRAW_MOTION;
1720 case OP_FLAG_MESSAGE:
1727 if (Context->magic == M_POP)
1730 mutt_error _("Can't change 'important' flag on POP server.");
1736 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1740 if (Context->magic == M_NNTP)
1743 mutt_error _("Can't change 'important' flag on NNTP server.");
1750 for (j = 0; j < Context->vcount; j++)
1752 if (Context->hdrs[Context->v2r[j]]->tagged)
1753 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1754 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1757 menu->redraw |= REDRAW_INDEX;
1761 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1762 if (option (OPTRESOLVE))
1764 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1766 menu->current = menu->oldcurrent;
1767 menu->redraw = REDRAW_CURRENT;
1770 menu->redraw = REDRAW_MOTION_RESYNCH;
1773 menu->redraw = REDRAW_CURRENT;
1775 menu->redraw |= REDRAW_STATUS;
1785 CHECK_IMAP_ACL(IMAP_ACL_SEEN);
1790 for (j = 0; j < Context->vcount; j++)
1792 if (Context->hdrs[Context->v2r[j]]->tagged)
1794 if (Context->hdrs[Context->v2r[j]]->read ||
1795 Context->hdrs[Context->v2r[j]]->old)
1796 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW, 1);
1798 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ, 1);
1801 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1805 if (CURHDR->read || CURHDR->old)
1806 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1808 mutt_set_flag (Context, CURHDR, M_READ, 1);
1810 if (option (OPTRESOLVE))
1812 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1814 menu->current = menu->oldcurrent;
1815 menu->redraw = REDRAW_CURRENT;
1818 menu->redraw = REDRAW_MOTION_RESYNCH;
1821 menu->redraw = REDRAW_CURRENT;
1822 menu->redraw |= REDRAW_STATUS;
1826 case OP_TOGGLE_WRITE:
1829 if (mx_toggle_write (Context) == 0)
1830 menu->redraw |= REDRAW_STATUS;
1833 case OP_MAIN_NEXT_THREAD:
1834 case OP_MAIN_NEXT_SUBTHREAD:
1835 case OP_MAIN_PREV_THREAD:
1836 case OP_MAIN_PREV_SUBTHREAD:
1842 case OP_MAIN_NEXT_THREAD:
1843 menu->current = mutt_next_thread (CURHDR);
1846 case OP_MAIN_NEXT_SUBTHREAD:
1847 menu->current = mutt_next_subthread (CURHDR);
1850 case OP_MAIN_PREV_THREAD:
1851 menu->current = mutt_previous_thread (CURHDR);
1854 case OP_MAIN_PREV_SUBTHREAD:
1855 menu->current = mutt_previous_subthread (CURHDR);
1859 if (menu->current < 0)
1861 menu->current = menu->oldcurrent;
1862 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1863 mutt_error _("No more threads.");
1865 mutt_error _("You are on the first thread.");
1867 else if (menu->menu == MENU_PAGER)
1869 op = OP_DISPLAY_MESSAGE;
1873 menu->redraw = REDRAW_MOTION;
1876 case OP_MAIN_PARENT_MESSAGE:
1881 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0)
1883 menu->current = menu->oldcurrent;
1885 else if (menu->menu == MENU_PAGER)
1887 op = OP_DISPLAY_MESSAGE;
1891 menu->redraw = REDRAW_MOTION;
1894 case OP_MAIN_SET_FLAG:
1895 case OP_MAIN_CLEAR_FLAG:
1902 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1905 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0)
1907 menu->redraw = REDRAW_STATUS;
1909 menu->redraw |= REDRAW_INDEX;
1910 else if (option (OPTRESOLVE))
1912 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1914 menu->current = menu->oldcurrent;
1915 menu->redraw |= REDRAW_CURRENT;
1918 menu->redraw |= REDRAW_MOTION_RESYNCH;
1921 menu->redraw |= REDRAW_CURRENT;
1925 case OP_MAIN_COLLAPSE_THREAD:
1929 if ((Sort & SORT_MASK) != SORT_THREADS)
1931 mutt_error _("Threading is not enabled.");
1935 if (CURHDR->collapsed)
1937 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1938 mutt_set_virtual (Context);
1939 if (option (OPTUNCOLLAPSEJUMP))
1940 menu->current = mutt_thread_next_unread (Context, CURHDR);
1942 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1944 menu->current = mutt_collapse_thread (Context, CURHDR);
1945 mutt_set_virtual (Context);
1949 mutt_error _("Thread contains unread messages.");
1953 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1957 case OP_MAIN_COLLAPSE_ALL:
1961 if ((Sort & SORT_MASK) != SORT_THREADS)
1963 mutt_error _("Threading is not enabled.");
1969 THREAD *thread, *top;
1972 if (CURHDR->collapsed)
1973 final = mutt_uncollapse_thread (Context, CURHDR);
1974 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1975 final = mutt_collapse_thread (Context, CURHDR);
1977 final = CURHDR->virtual;
1979 base = Context->hdrs[Context->v2r[final]];
1981 top = Context->tree;
1982 Context->collapsed = !Context->collapsed;
1983 while ((thread = top) != NULL)
1985 while (!thread->message)
1986 thread = thread->child;
1987 h = thread->message;
1989 if (h->collapsed != Context->collapsed)
1992 mutt_uncollapse_thread (Context, h);
1993 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1994 mutt_collapse_thread (Context, h);
1999 mutt_set_virtual (Context);
2000 for (j = 0; j < Context->vcount; j++)
2002 if (Context->hdrs[Context->v2r[j]]->index == base->index)
2009 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2013 /* --------------------------------------------------------------------
2014 * These functions are invoked directly from the internal-pager
2017 case OP_BOUNCE_MESSAGE:
2022 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
2025 case OP_CREATE_ALIAS:
2027 mutt_create_alias (Context && Context->vcount ? CURHDR->env : NULL, NULL);
2028 MAYBE_REDRAW (menu->redraw);
2029 menu->redraw |= REDRAW_CURRENT;
2034 mutt_query_menu (NULL, 0);
2035 MAYBE_REDRAW (menu->redraw);
2038 case OP_PURGE_MESSAGE:
2046 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2051 mutt_tag_set_flag (M_DELETE, 1);
2052 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
2053 if (option (OPTDELETEUNTAG))
2054 mutt_tag_set_flag (M_TAG, 0);
2055 menu->redraw = REDRAW_INDEX;
2059 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
2060 mutt_set_flag (Context, CURHDR, M_PURGED,
2061 (op != OP_PURGE_MESSAGE) ? 0 : 1);
2062 if (option (OPTDELETEUNTAG))
2063 mutt_set_flag (Context, CURHDR, M_TAG, 0);
2064 if (option (OPTRESOLVE))
2066 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
2068 menu->current = menu->oldcurrent;
2069 menu->redraw = REDRAW_CURRENT;
2071 else if (menu->menu == MENU_PAGER)
2073 op = OP_DISPLAY_MESSAGE;
2077 menu->redraw |= REDRAW_MOTION_RESYNCH;
2080 menu->redraw = REDRAW_CURRENT;
2082 menu->redraw |= REDRAW_STATUS;
2085 case OP_DELETE_THREAD:
2086 case OP_DELETE_SUBTHREAD:
2093 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2096 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
2097 op == OP_DELETE_THREAD ? 0 : 1);
2101 if (option (OPTDELETEUNTAG))
2102 mutt_thread_set_flag (CURHDR, M_TAG, 0,
2103 op == OP_DELETE_THREAD ? 0 : 1);
2104 if (option (OPTRESOLVE))
2105 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
2106 menu->current = menu->oldcurrent;
2107 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2113 if (Context && Context->magic == M_NNTP)
2115 if (mutt_newsgroup_catchup (CurrentNewsSrv,
2116 ((NNTP_DATA *)Context->data)->group))
2117 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2122 case OP_DISPLAY_ADDRESS:
2126 mutt_display_address (CURHDR->env);
2129 case OP_ENTER_COMMAND:
2131 CurrentMenu = MENU_MAIN;
2132 mutt_enter_command ();
2133 mutt_check_rescore (Context);
2134 if (option (OPTFORCEREDRAWINDEX))
2135 menu->redraw = REDRAW_FULL;
2136 unset_option (OPTFORCEREDRAWINDEX);
2137 unset_option (OPTFORCEREDRAWPAGER);
2140 case OP_EDIT_MESSAGE:
2148 if (Context->magic == M_POP)
2151 mutt_error _("Can't edit message on POP server.");
2157 CHECK_IMAP_ACL(IMAP_ACL_INSERT);
2161 if (Context->magic == M_NNTP)
2164 mutt_error _("Can't edit message on newsserver.");
2169 if (option (OPTPGPAUTODEC) && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2170 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2171 mutt_edit_message (Context, tag ? NULL : CURHDR);
2172 menu->redraw = REDRAW_FULL;
2176 case OP_FORWARD_MESSAGE:
2181 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2182 menu->redraw = REDRAW_FULL;
2186 case OP_FORGET_PASSPHRASE:
2187 crypt_forget_passphrase ();
2190 case OP_GROUP_REPLY:
2195 ci_send_message (SENDREPLY|SENDGROUPREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2196 menu->redraw = REDRAW_FULL;
2204 ci_send_message (SENDREPLY|SENDLISTREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2205 menu->redraw = REDRAW_FULL;
2211 ci_send_message (0, NULL, NULL, Context, NULL);
2212 menu->redraw = REDRAW_FULL;
2216 if (!(WithCrypto & APPLICATION_PGP))
2219 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2220 menu->redraw = REDRAW_FULL;
2224 case OP_EXTRACT_KEYS:
2229 crypt_extract_keys_from_messages(tag ? NULL : CURHDR);
2230 menu->redraw = REDRAW_FULL;
2234 case OP_CHECK_TRADITIONAL:
2235 if (!(WithCrypto & APPLICATION_PGP))
2239 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2240 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2242 if (menu->menu == MENU_PAGER)
2244 op = OP_DISPLAY_MESSAGE;
2253 mutt_pipe_message (tag ? NULL : CURHDR);
2254 MAYBE_REDRAW (menu->redraw);
2261 mutt_print_message (tag ? NULL : CURHDR);
2264 case OP_MAIN_READ_THREAD:
2265 case OP_MAIN_READ_SUBTHREAD:
2272 CHECK_IMAP_ACL(IMAP_ACL_SEEN);
2275 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2276 op == OP_MAIN_READ_THREAD ? 0 : 1);
2280 if (option (OPTRESOLVE))
2282 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2283 mutt_next_thread (CURHDR) : mutt_next_subthread (CURHDR))) == -1)
2284 menu->current = menu->oldcurrent;
2286 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2290 case OP_RECALL_MESSAGE:
2293 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2294 menu->redraw = REDRAW_FULL;
2305 for (j = 0; j < Context->vcount; j++)
2307 if (Context->hdrs[Context->v2r[j]]->tagged)
2308 mutt_resend_message (NULL, Context, Context->hdrs[Context->v2r[j]]);
2312 mutt_resend_message (NULL, Context, CURHDR);
2314 menu->redraw = REDRAW_FULL;
2320 case OP_FORWARD_TO_GROUP:
2323 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2324 Context && Context->msgcount == 0) {
2325 mutt_error (_("There are no messages."));
2327 } else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2328 mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2329 query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != M_YES)
2331 if (Context && Context->magic == M_NNTP &&
2332 !((NNTP_DATA *)Context->data)->allowed &&
2333 query_quadoption (OPT_TOMODERATED, _("Posting to this group not allowed, may be moderated. Continue?")) != M_YES)
2336 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2340 if (op == OP_FOLLOWUP)
2341 ci_send_message (SENDNEWS|SENDREPLY, NULL, NULL, Context,
2342 tag ? NULL : CURHDR);
2344 ci_send_message (SENDNEWS|SENDFORWARD, NULL, NULL, Context,
2345 tag ? NULL : CURHDR);
2347 menu->redraw = REDRAW_FULL;
2357 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2358 menu->redraw = REDRAW_FULL;
2361 case OP_SHELL_ESCAPE:
2363 mutt_shell_escape ();
2364 MAYBE_REDRAW (menu->redraw);
2368 case OP_TAG_SUBTHREAD:
2372 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2373 op == OP_TAG_THREAD ? 0 : 1);
2377 if (option (OPTRESOLVE))
2379 menu->current = mutt_next_thread (CURHDR);
2381 if (menu->current == -1)
2382 menu->current = menu->oldcurrent;
2384 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2395 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2400 mutt_tag_set_flag (M_DELETE, 0);
2401 mutt_tag_set_flag (M_PURGED, 0);
2402 menu->redraw = REDRAW_INDEX;
2406 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2407 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2408 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1)
2411 menu->redraw = REDRAW_MOTION_RESYNCH;
2414 menu->redraw = REDRAW_CURRENT;
2416 menu->redraw |= REDRAW_STATUS;
2419 case OP_UNDELETE_THREAD:
2420 case OP_UNDELETE_SUBTHREAD:
2427 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2430 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2431 op == OP_UNDELETE_THREAD ? 0 : 1)
2432 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2433 op == OP_UNDELETE_THREAD ? 0 : 1);
2437 if (option (OPTRESOLVE))
2439 if (op == OP_UNDELETE_THREAD)
2440 menu->current = mutt_next_thread (CURHDR);
2442 menu->current = mutt_next_subthread (CURHDR);
2444 if (menu->current == -1)
2445 menu->current = menu->oldcurrent;
2447 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2457 menu->redraw = REDRAW_FULL;
2460 case OP_VIEW_ATTACHMENTS:
2463 mutt_view_attachments (CURHDR);
2464 if (CURHDR->attach_del)
2465 Context->changed = 1;
2466 menu->redraw = REDRAW_FULL;
2476 case OP_SIDEBAR_SCROLL_UP:
2477 case OP_SIDEBAR_SCROLL_DOWN:
2478 case OP_SIDEBAR_NEXT:
2479 case OP_SIDEBAR_PREV:
2480 case OP_SIDEBAR_NEXT_NEW:
2481 case OP_SIDEBAR_PREV_NEW:
2482 scroll_sidebar(op, menu->menu);
2485 if (menu->menu == MENU_MAIN)
2486 km_error_key (MENU_MAIN);
2489 if (menu->menu == MENU_PAGER)
2491 menu->menu = MENU_MAIN;
2492 menu->redraw = REDRAW_FULL;
2494 set_option (OPTWEED); /* turn header weeding back on. */
2502 /* Close all open IMAP connections */
2507 /* Close all open NNTP connections */
2512 mutt_menuDestroy (&menu);
2516 void mutt_set_header_color (CONTEXT *ctx, HEADER *curhdr)
2523 for (color = ColorIndexList; color; color = color->next)
2524 if (mutt_pattern_exec (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr))
2526 curhdr->pair = color->pair;
2529 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];