2 * Copyright notice from original mutt:
3 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
5 * Parts were written/modified by:
6 * Nico Golde <nico@ngolde.de>
8 * This file is part of mutt-ng, see http://www.muttng.org/.
9 * It's licensed under the GNU General Public License,
10 * please see the file GPL in the top level source directory.
13 #include <lib-lib/lib-lib.h>
15 #include <lib-ui/sidebar.h>
16 #include <lib-mx/mx.h>
27 #include "recvattach.h"
32 #include <imap/imap_private.h>
35 #include <nntp/nntp.h>
38 static const char *No_mailbox_is_open = N_("No mailbox is open.");
39 static const char *There_are_no_messages = N_("There are no messages.");
40 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
41 static const char *Function_not_permitted_in_attach_message_mode =
42 N_("Function not permitted in attach-message mode.");
43 static const char *No_visible = N_("No visible messages.");
45 #define CHECK_IN_MAILBOX if (!Context) \
48 mutt_error (_(No_mailbox_is_open)); \
52 #define CHECK_MSGCOUNT if (!Context) \
55 mutt_error(_(No_mailbox_is_open)); \
58 else if (!Context->msgcount) \
61 mutt_error(_(There_are_no_messages)); \
65 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
68 mutt_error(_(No_visible)); \
73 #define CHECK_READONLY if (Context->readonly) \
76 mutt_error(_(Mailbox_is_read_only)); \
80 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
83 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
87 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
88 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
89 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
90 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
92 extern size_t UngetCount;
94 void index_make_entry (char *s, ssize_t l, struct menu_t * menu, int num)
96 format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_INDEX;
97 int edgemsgno, reverse = Sort & SORT_REVERSE;
98 HEADER *h = Context->hdrs[Context->v2r[num]];
101 if (option(OPTARROWCURSOR))
102 flag |= M_FORMAT_ARROWCURSOR;
104 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
105 flag |= M_FORMAT_TREE; /* display the thread tree */
106 if (h->display_subject)
107 flag |= M_FORMAT_FORCESUBJ;
110 if (menu->top + menu->pagelen > menu->max)
111 edgemsgno = Context->v2r[menu->max - 1];
113 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
116 edgemsgno = Context->v2r[menu->top];
118 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
122 /* if no ancestor is visible on current screen, provisionally force
124 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
126 flag |= M_FORMAT_FORCESUBJ;
129 else if (tmp->message->virtual >= 0)
132 if (flag & M_FORMAT_FORCESUBJ) {
133 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
137 /* ...but if a previous sibling is available, don't force it */
138 if (reverse ? tmp->message->msgno >
139 edgemsgno : tmp->message->msgno < edgemsgno)
141 else if (tmp->message->virtual >= 0) {
142 flag &= ~M_FORMAT_FORCESUBJ;
150 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
153 int index_color (int index_no)
155 HEADER *h = Context->hdrs[Context->v2r[index_no]];
160 mutt_set_header_color (Context, h);
164 static int ci_next_undeleted (int msgno)
168 for (i = msgno + 1; i < Context->vcount; i++)
169 if (!Context->hdrs[Context->v2r[i]]->deleted)
174 static int ci_previous_undeleted (int msgno)
178 for (i = msgno - 1; i >= 0; i--)
179 if (!Context->hdrs[Context->v2r[i]]->deleted)
184 /* Return the index of the first new message, or failing that, the first
187 static int ci_first_message (void)
191 if (Context && Context->msgcount) {
192 for (i = 0; i < Context->vcount; i++) {
193 if (!Context->hdrs[Context->v2r[i]]->read &&
194 !Context->hdrs[Context->v2r[i]]->deleted) {
195 if (!Context->hdrs[Context->v2r[i]]->old)
204 /* If Sort is reverse and not threaded, the latest message is first.
205 * If Sort is threaded, the latest message is first iff exactly one
206 * of Sort and SortAux are reverse.
208 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
209 ((Sort & SORT_MASK) == SORT_THREADS &&
210 ((Sort ^ SortAux) & SORT_REVERSE)))
213 return (Context->vcount ? Context->vcount - 1 : 0);
218 /* This should be in mx.c, but it only gets used here. */
219 static int mx_toggle_write (CONTEXT * ctx)
225 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
230 if (ctx->dontwrite) {
232 mutt_message (_("Changes to folder will be written on folder exit."));
236 mutt_message (_("Changes to folder will not be written."));
242 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
243 int oldcount, int index_hint)
245 /* store pointers to the newly added messages */
246 HEADER **save_new = NULL;
249 /* take note of the current message */
251 if (menu->current < Context->vcount)
252 menu->oldcurrent = index_hint;
254 oldcount = 0; /* invalid message number! */
257 /* We are in a limited view. Check if the new message(s) satisfy
258 * the limit criteria. If they do, set their virtual msgno so that
259 * they will be visible in the limited view */
260 if (Context->pattern) {
261 #define THIS_BODY Context->hdrs[j]->content
262 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
263 if (mutt_pattern_exec
264 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
266 Context->hdrs[j]->virtual = Context->vcount;
267 Context->v2r[Context->vcount] = j;
268 Context->hdrs[j]->limited = 1;
271 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
277 /* save the list of new messages */
278 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
279 save_new = p_new(HEADER*, Context->msgcount - oldcount);
280 for (j = oldcount; j < Context->msgcount; j++)
281 save_new[j - oldcount] = Context->hdrs[j];
284 /* if the mailbox was reopened, need to rethread from scratch */
285 mutt_sort_headers (Context, (check == M_REOPENED));
287 /* uncollapse threads with new mail */
288 if ((Sort & SORT_MASK) == SORT_THREADS) {
289 if (check == M_REOPENED) {
292 Context->collapsed = 0;
294 for (h = Context->tree; h; h = h->next) {
295 for (c = h; !c->message; c = c->child);
296 mutt_uncollapse_thread (Context, c->message);
298 mutt_set_virtual (Context);
301 for (j = 0; j < Context->msgcount - oldcount; j++) {
304 for (k = 0; k < Context->msgcount; k++) {
305 HEADER *h = Context->hdrs[k];
307 if (h == save_new[j] && (!Context->pattern || h->limited))
308 mutt_uncollapse_thread (Context, h);
312 mutt_set_virtual (Context);
318 /* restore the current message to the message it was pointing to */
319 for (j = 0; j < Context->vcount; j++) {
320 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
327 if (menu->current < 0)
328 menu->current = ci_first_message ();
331 static void resort_index (MUTTMENU * menu)
334 HEADER *current = CURHDR;
337 mutt_sort_headers (Context, 0);
338 /* Restore the current message */
340 for (i = 0; i < Context->vcount; i++) {
341 if (Context->hdrs[Context->v2r[i]] == current) {
347 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
348 menu->current = mutt_parent_message (Context, current);
350 if (menu->current < 0)
351 menu->current = ci_first_message ();
353 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
356 struct mapping_t IndexHelp[] = {
357 {N_("Quit"), OP_QUIT},
358 {N_("Del"), OP_DELETE},
359 {N_("Undel"), OP_UNDELETE},
360 {N_("Save"), OP_SAVE},
361 {N_("Mail"), OP_MAIL},
362 {N_("Reply"), OP_REPLY},
363 {N_("Group"), OP_GROUP_REPLY},
364 {N_("Help"), OP_HELP},
369 struct mapping_t IndexNewsHelp[] = {
370 {N_("Quit"), OP_QUIT},
371 {N_("Del"), OP_DELETE},
372 {N_("Undel"), OP_UNDELETE},
373 {N_("Save"), OP_SAVE},
374 {N_("Post"), OP_POST},
375 {N_("Followup"), OP_FOLLOWUP},
376 {N_("Catchup"), OP_CATCHUP},
377 {N_("Help"), OP_HELP},
382 /* This function handles the message index window as well as commands returned
383 * from the pager (MENU_PAGER).
385 int mutt_index_menu (void)
387 char buf[LONG_STRING], helpstr[STRING];
390 int done = 0; /* controls when to exit the "event" loop */
392 int tag = 0; /* has the tag-prefix command been pressed? */
397 const char *cp; /* temporary variable. */
398 int index_hint; /* used to restore cursor position */
399 int do_buffy_notify = 1;
400 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
401 int attach_msg = option (OPTATTACHMSG);
403 menu = mutt_new_menu ();
404 menu->menu = MENU_MAIN;
406 menu->pagelen = LINES - 3;
407 menu->make_entry = (void *) index_make_entry;
408 menu->color = index_color;
409 menu->current = ci_first_message ();
410 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
413 && (Context->magic ==
414 M_NNTP)) ? IndexNewsHelp :
419 buffy_check (0); /* force the buffy check after we enter the folder */
420 /* record folder we open to place sidebar indicator properly */
421 if (Context && Context->path)
422 sidebar_set_current (Context->path);
426 tag = 0; /* clear the tag-prefix */
428 menu->max = Context ? Context->vcount : 0;
429 oldcount = Context ? Context->msgcount : 0;
431 /* check if we need to resort the index because just about
432 * any 'op' below could do mutt_enter_command(), either here or
433 * from any new menu launched, and change $sort/$sort_aux
435 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
438 if (option (OPTREDRAWTREE) && Context && Context->msgcount
439 && (Sort & SORT_MASK) == SORT_THREADS) {
440 mutt_draw_tree (Context);
441 menu->redraw |= REDRAW_STATUS;
442 unset_option (OPTREDRAWTREE);
445 if (Context && !attach_msg) {
448 /* check for new mail in the mailbox. If nonzero, then something has
449 * changed about the file (either we got new mail or the file was
450 * modified underneath us.)
453 imap_allow_reopen (Context);
455 index_hint = (Context->vcount && menu->current >= 0
456 && menu->current < Context->vcount) ? CURHDR->index : 0;
458 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
459 if (!Context->path) {
460 /* fatal error occurred */
462 menu->redraw = REDRAW_FULL;
464 set_option (OPTSEARCHINVALID);
466 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
467 update_index (menu, Context, check, oldcount, index_hint);
469 /* notify the user of new mail */
470 if (check == M_REOPENED)
472 ("Mailbox was externally modified. Flags may be wrong."));
473 else if (check == M_NEW_MAIL) {
474 /* on new mail: redraw sidebar */
476 mutt_message (_("New mail in this mailbox."));
481 else if (check == M_FLAGS)
482 mutt_message (_("Mailbox was externally modified."));
484 /* avoid the message being overwritten by buffy */
487 menu->redraw = REDRAW_FULL;
488 menu->max = Context->vcount;
490 set_option (OPTSEARCHINVALID);
495 imap_disallow_reopen (Context);
498 /* check for new mail in the incoming folders */
500 if ((newcount = buffy_check (0)) != oldcount) {
501 menu->redraw |= REDRAW_STATUS;
502 menu->redraw |= REDRAW_SIDEBAR;
504 if (do_buffy_notify) {
505 if (buffy_notify () && MCore.beep_new)
514 if (menu->redraw & REDRAW_SIDEBAR)
516 if (menu->redraw & REDRAW_FULL) {
517 menu_redraw_full (menu);
522 if (menu->menu == MENU_MAIN) {
523 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
524 menu_check_recenter (menu);
526 if (menu->redraw & REDRAW_INDEX) {
527 menu_redraw_index (menu);
528 menu->redraw |= REDRAW_STATUS;
530 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
531 menu_redraw_motion (menu);
532 else if (menu->redraw & REDRAW_CURRENT)
533 menu_redraw_current (menu);
536 if (menu->redraw & REDRAW_STATUS) {
537 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
538 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
539 sidebar_draw_frames();
540 SETCOLOR (MT_COLOR_STATUS);
541 BKGDSET (MT_COLOR_STATUS);
542 move(option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
543 mutt_paddstr (COLS-SW, buf);
544 SETCOLOR (MT_COLOR_NORMAL);
545 BKGDSET (MT_COLOR_NORMAL);
546 sidebar_set_buffystats (Context);
547 menu->redraw &= ~REDRAW_STATUS;
548 if (option (OPTXTERMSETTITLES)) {
549 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermTitle));
550 printf("\033]2;%s\007", buf);
551 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermIcon));
552 printf("\033]1;%s\007", buf);
558 if (menu->current < menu->max)
559 menu->oldcurrent = menu->current;
561 menu->oldcurrent = -1;
563 if (option (OPTARROWCURSOR))
564 move (menu->current - menu->top + menu->offset, 2);
565 else if (option (OPTBRAILLEFRIENDLY))
566 move (menu->current - menu->top + menu->offset, 0);
568 move (menu->current - menu->top + menu->offset, COLS - 1);
571 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
574 mutt_resize_screen ();
575 menu->redraw = REDRAW_FULL;
576 menu->menu = MENU_MAIN;
578 menu->top = 0; /* so we scroll the right amount */
580 * force a real complete redraw. clrtobot() doesn't seem to be able
581 * to handle every case without this.
583 clearok (stdscr, TRUE);
588 op = km_dokey (MENU_MAIN);
591 continue; /* either user abort or timeout */
595 /* special handling for the tag-prefix function */
596 if (op == OP_TAG_PREFIX) {
598 mutt_error (_("No mailbox is open."));
603 if (!Context->tagged) {
604 mutt_error (_("No tagged messages."));
610 /* give visual indication that the next command is a tag- command */
611 mvaddstr (LINES - 1, 0, "tag-");
614 /* get the real command */
615 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
616 /* abort tag sequence */
617 CLEARLINE (LINES - 1);
621 else if (option (OPTAUTOTAG) && Context && Context->tagged)
624 if (op == OP_TAG_PREFIX_COND) {
626 mutt_error (_("No mailbox is open."));
631 if (!Context->tagged) {
634 while (UngetCount > 0) {
636 if (tmp.op == OP_END_COND)
639 mutt_message (_("Nothing to do."));
645 /* give visual indication that the next command is a tag- command */
646 mvaddstr (LINES - 1, 0, "tag-");
649 /* get the real command */
650 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
651 /* abort tag sequence */
652 CLEARLINE (LINES - 1);
660 if (menu->current < menu->max)
661 menu->oldcurrent = menu->current;
663 menu->oldcurrent = -1;
665 mutt_curs_set (1); /* fallback from the pager */
669 unset_option (OPTNEWS); /* for any case */
674 /* ----------------------------------------------------------------------
679 menu_bottom_page (menu);
682 menu_first_entry (menu);
685 menu_middle_page (menu);
691 menu_half_down (menu);
694 menu_next_line (menu);
697 menu_prev_line (menu);
700 menu_next_page (menu);
703 menu_prev_page (menu);
706 menu_last_entry (menu);
709 menu_top_page (menu);
712 menu_current_top (menu);
714 case OP_CURRENT_MIDDLE:
715 menu_current_middle (menu);
717 case OP_CURRENT_BOTTOM:
718 menu_current_bottom (menu);
725 if (Context->magic == M_NNTP) {
728 if (op == OP_GET_MESSAGE) {
730 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
735 string_list_t *ref = CURHDR->env->references;
738 mutt_error (_("Article has no parent reference!"));
742 m_strcpy(buf, sizeof(buf), ref->data);
744 if (!Context->id_hash)
745 Context->id_hash = mutt_make_id_hash (Context);
746 if ((h = hash_find (Context->id_hash, buf))) {
747 if (h->virtual != -1) {
748 menu->current = h->virtual;
749 menu->redraw = REDRAW_MOTION_RESYNCH;
751 else if (h->collapsed) {
752 mutt_uncollapse_thread (Context, h);
753 mutt_set_virtual (Context);
754 menu->current = h->virtual;
755 menu->redraw = REDRAW_MOTION_RESYNCH;
758 mutt_error (_("Message not visible in limited view."));
761 if (nntp_check_msgid (Context, buf) == 0) {
762 h = Context->hdrs[Context->msgcount - 1];
763 mutt_sort_headers (Context, 0);
764 menu->current = h->virtual;
765 menu->redraw = REDRAW_FULL;
768 mutt_error (_("Article %s not found on server"), buf);
773 case OP_GET_CHILDREN:
774 case OP_RECONSTRUCT_THREAD:
776 if (Context->magic == M_NNTP) {
778 int old = CURHDR->index;
780 if (!CURHDR->env->message_id) {
781 mutt_error (_("No Message-ID. Unable to perform operation"));
786 if (!Context->id_hash)
787 Context->id_hash = mutt_make_id_hash (Context);
788 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
790 if (op == OP_RECONSTRUCT_THREAD) {
791 string_list_t *ref = CURHDR->env->references;
794 nntp_check_msgid (Context, ref->data);
795 /* the last msgid in References is the root message */
797 m_strcpy(buf, sizeof(buf), ref->data);
801 mutt_message (_("Check for children of message..."));
803 if (nntp_check_children (Context, buf) == 0) {
804 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
805 h = hash_find (Context->id_hash, buf);
806 /* if the root message was retrieved, move to it */
808 menu->current = h->virtual;
809 else /* try to restore old position */
810 for (i = 0; i < Context->msgcount; i++)
811 if (Context->hdrs[i]->index == old) {
812 menu->current = Context->hdrs[i]->virtual;
813 /* As an added courtesy, recenter the menu
814 * with the current entry at the middle of the screen */
815 menu_check_recenter (menu);
816 menu_current_middle (menu);
819 menu->redraw = REDRAW_FULL;
829 if (isdigit (LastKey))
830 mutt_ungetch (LastKey, 0);
832 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
836 if (!isdigit ((unsigned char) buf[0])) {
837 mutt_error (_("Argument must be a message number."));
843 if (i > 0 && i <= Context->msgcount) {
844 for (j = i - 1; j < Context->msgcount; j++) {
845 if (Context->hdrs[j]->virtual != -1)
848 if (j >= Context->msgcount) {
849 for (j = i - 2; j >= 0; j--) {
850 if (Context->hdrs[j]->virtual != -1)
856 menu->current = Context->hdrs[j]->virtual;
857 if (menu->menu == MENU_PAGER) {
858 op = OP_DISPLAY_MESSAGE;
862 menu->redraw = REDRAW_MOTION;
865 mutt_error (_("That message is not visible."));
868 mutt_error (_("Invalid message number."));
872 /* --------------------------------------------------------------------
873 * `index' specific commands
876 case OP_MAIN_DELETE_PATTERN:
882 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
885 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
886 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
889 case OP_MAIN_FETCH_MAIL:
893 menu->redraw = REDRAW_FULL;
898 mutt_help (MENU_MAIN);
899 menu->redraw = REDRAW_FULL;
902 case OP_MAIN_SHOW_LIMIT:
904 if (!Context->pattern)
905 mutt_message (_("No limit pattern is in effect."));
910 /* i18n: ask for a limit to apply */
911 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
912 mutt_message ("%s", buffer);
920 menu->oldcurrent = (Context->vcount && menu->current >= 0
922 Context->vcount) ? CURHDR->index : -1;
923 if (op == OP_TOGGLE_READ) {
924 char buffer[LONG_STRING];
926 if (m_strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
927 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
928 Context->pattern ? Context->pattern : ".*");
929 set_option (OPTHIDEREAD);
932 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
933 if (m_strncmp (buf, ".*", 2) == 0)
934 snprintf (buf, sizeof (buf), "~A");
935 unset_option (OPTHIDEREAD);
937 p_delete(&Context->pattern);
938 Context->pattern = m_strdup(buf);
940 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
941 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
943 if (menu->oldcurrent >= 0) {
944 /* try to find what used to be the current message */
946 for (i = 0; i < Context->vcount; i++)
947 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
951 if (menu->current < 0)
956 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
957 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
958 mutt_draw_tree (Context);
959 menu->redraw = REDRAW_FULL;
961 if (Context->pattern)
962 mutt_message _("To view all messages, limit to \"all\".");
973 if (query_quadoption2(MCore.quit, _("Quit Madmutt?")) == M_YES) {
976 oldcount = Context ? Context->msgcount : 0;
979 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
982 if (check == M_NEW_MAIL || check == M_REOPENED)
983 update_index (menu, Context, check, oldcount, index_hint);
985 menu->redraw = REDRAW_FULL; /* new mail arrived? */
986 set_option (OPTSEARCHINVALID);
993 clearok (stdscr, TRUE);
994 menu->redraw = REDRAW_FULL;
998 case OP_SEARCH_REVERSE:
1000 case OP_SEARCH_OPPOSITE:
1004 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1005 menu->current = menu->oldcurrent;
1007 menu->redraw = REDRAW_MOTION;
1011 case OP_SORT_REVERSE:
1013 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
1014 if (Context && Context->msgcount) {
1015 resort_index (menu);
1016 set_option (OPTSEARCHINVALID);
1025 if (tag && !option (OPTAUTOTAG)) {
1026 for (j = 0; j < Context->vcount; j++)
1027 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1028 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1031 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1032 Context->last_tag = CURHDR->tagged ? CURHDR :
1033 ((Context->last_tag == CURHDR && !CURHDR->tagged)
1034 ? NULL : Context->last_tag);
1035 menu->redraw = REDRAW_STATUS;
1036 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
1038 menu->redraw |= REDRAW_MOTION_RESYNCH;
1041 menu->redraw |= REDRAW_CURRENT;
1045 case OP_MAIN_TAG_PATTERN:
1049 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1050 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1053 case OP_MAIN_UNDELETE_PATTERN:
1059 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1061 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1063 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1066 case OP_MAIN_UNTAG_PATTERN:
1070 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1071 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1074 /* --------------------------------------------------------------------
1075 * The following operations can be performed inside of the pager.
1078 case OP_MAIN_IMAP_FETCH:
1079 if (Context->magic == M_IMAP)
1080 imap_check_mailbox (Context, &index_hint, 1);
1083 case OP_MAIN_SYNC_FOLDER:
1085 if (Context && !Context->msgcount)
1092 int oldvcount = Context->vcount;
1093 oldcount = Context->msgcount;
1097 /* calculate the number of messages _above_ the cursor,
1098 * so we can keep the cursor on the current message
1100 for (j = 0; j <= menu->current; j++) {
1101 if (Context->hdrs[Context->v2r[j]]->deleted)
1105 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1106 if (Context->vcount != oldvcount)
1107 menu->current -= dcount;
1108 set_option (OPTSEARCHINVALID);
1110 else if (check == M_NEW_MAIL || check == M_REOPENED)
1111 update_index (menu, Context, check, oldcount, index_hint);
1114 * do a sanity check even if mx_sync_mailbox failed.
1117 if (menu->current < 0 || menu->current >= Context->vcount)
1118 menu->current = ci_first_message ();
1121 /* check for a fatal error, or all messages deleted */
1125 /* if we were in the pager, redisplay the message */
1126 if (menu->menu == MENU_PAGER) {
1127 op = OP_DISPLAY_MESSAGE;
1131 menu->redraw = REDRAW_FULL;
1134 case OP_SIDEBAR_OPEN:
1135 case OP_MAIN_CHANGE_FOLDER:
1136 case OP_MAIN_CHANGE_FOLDER_READONLY:
1138 case OP_MAIN_CHANGE_GROUP:
1139 case OP_MAIN_CHANGE_GROUP_READONLY:
1141 if (attach_msg || option (OPTREADONLY) ||
1143 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1145 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1151 cp = _("Open mailbox in read-only mode");
1153 cp = _("Open mailbox");
1157 unset_option (OPTNEWS);
1158 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1159 set_option (OPTNEWS);
1160 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1163 cp = _("Open newsgroup in read-only mode");
1165 cp = _("Open newsgroup");
1166 nntp_buffy (buf, sizeof (buf));
1171 if (Context && Context->path)
1172 m_strcpy(buf, sizeof(buf), Context->path);
1173 if (op != OP_SIDEBAR_OPEN)
1174 buffy_next (buf, sizeof (buf));
1177 if (op == OP_SIDEBAR_OPEN) {
1178 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1180 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1181 if (menu->menu == MENU_PAGER) {
1182 op = OP_DISPLAY_MESSAGE;
1188 CLEARLINE (LINES - 1);
1193 if (option (OPTNEWS)) {
1194 unset_option (OPTNEWS);
1195 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1199 mutt_expand_path (buf, sizeof (buf));
1200 if (mx_get_magic (buf) <= 0) {
1201 mutt_error (_("%s is not a mailbox."), buf);
1204 m_strreplace(&CurrentFolder, buf);
1209 if (Context->cinfo && Context->realpath)
1210 m_strreplace(&LastFolder, Context->realpath);
1212 m_strreplace(&LastFolder, Context->path);
1213 oldcount = Context ? Context->msgcount : 0;
1215 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1216 if (check == M_NEW_MAIL || check == M_REOPENED)
1217 update_index (menu, Context, check, oldcount, index_hint);
1219 set_option (OPTSEARCHINVALID);
1220 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1228 /* Set CurrentMenu to MENU_MAIN before executing any folder
1229 * hooks so that all the index menu functions are available to
1233 CurrentMenu = MENU_MAIN;
1234 mutt_folder_hook (buf);
1236 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1237 menu->current = ci_first_message ();
1241 sidebar_set_current (buf);
1244 /* buffy_check() must be done with mail-reader mode! */
1245 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1247 && (Context->magic ==
1248 M_NNTP)) ? IndexNewsHelp :
1251 mutt_clear_error ();
1252 buffy_check (0); /* force the buffy check after we have changed
1254 menu->redraw = REDRAW_FULL;
1255 set_option (OPTSEARCHINVALID);
1258 case OP_DISPLAY_MESSAGE:
1259 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1264 * toggle the weeding of headers so that a user can press the key
1265 * again while reading the message.
1267 if (op == OP_DISPLAY_HEADERS)
1268 toggle_option (OPTWEED);
1270 unset_option (OPTNEEDRESORT);
1272 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1273 mutt_uncollapse_thread (Context, CURHDR);
1274 mutt_set_virtual (Context);
1275 if (option (OPTUNCOLLAPSEJUMP))
1276 menu->current = mutt_thread_next_unread (Context, CURHDR);
1279 if (option (OPTPGPAUTODEC) &&
1280 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1281 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1283 if ((op = mutt_display_message (CURHDR)) == -1) {
1284 unset_option (OPTNEEDRESORT);
1288 menu->menu = MENU_PAGER;
1289 menu->oldcurrent = menu->current;
1295 if (menu->menu == MENU_MAIN && attach_msg) {
1300 if ((menu->menu == MENU_MAIN)
1301 && (query_quadoption2(MCore.quit,
1302 _("Exit Madmutt without saving?")) == M_YES))
1305 mx_fastclose_mailbox (Context);
1317 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1318 /* if we were in the pager, redisplay the message */
1319 if (menu->menu == MENU_PAGER) {
1320 op = OP_DISPLAY_MESSAGE;
1324 menu->redraw = REDRAW_CURRENT;
1327 case OP_MAIN_BREAK_THREAD:
1333 if ((Sort & SORT_MASK) != SORT_THREADS)
1334 mutt_error (_("Threading is not enabled."));
1338 HEADER *oldcur = CURHDR;
1340 mutt_break_thread (CURHDR);
1341 mutt_sort_headers (Context, 1);
1342 menu->current = oldcur->virtual;
1345 Context->changed = 1;
1346 mutt_message _("Thread broken");
1348 if (menu->menu == MENU_PAGER) {
1349 op = OP_DISPLAY_MESSAGE;
1353 menu->redraw |= REDRAW_INDEX;
1357 case OP_MAIN_LINK_THREADS:
1363 if ((Sort & SORT_MASK) != SORT_THREADS)
1364 mutt_error (_("Threading is not enabled."));
1366 else if (!CURHDR->env->message_id)
1367 mutt_error (_("No Message-ID: header available to link thread"));
1369 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1370 mutt_error (_("First, please tag a message to be linked here"));
1373 HEADER *oldcur = CURHDR;
1375 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1377 mutt_sort_headers (Context, 1);
1378 menu->current = oldcur->virtual;
1380 Context->changed = 1;
1381 mutt_message _("Threads linked");
1384 mutt_error (_("No thread linked"));
1387 if (menu->menu == MENU_PAGER) {
1388 op = OP_DISPLAY_MESSAGE;
1392 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1395 case OP_MAIN_NEXT_UNDELETED:
1399 if (menu->current >= Context->vcount - 1) {
1400 if (menu->menu == MENU_MAIN)
1401 mutt_error (_("You are on the last message."));
1405 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1406 menu->current = menu->oldcurrent;
1407 if (menu->menu == MENU_MAIN)
1408 mutt_error (_("No undeleted messages."));
1410 else if (menu->menu == MENU_PAGER) {
1411 op = OP_DISPLAY_MESSAGE;
1415 menu->redraw = REDRAW_MOTION;
1422 if (menu->current >= Context->vcount - 1) {
1423 if (menu->menu == MENU_MAIN)
1424 mutt_error (_("You are on the last message."));
1429 if (menu->menu == MENU_PAGER) {
1430 op = OP_DISPLAY_MESSAGE;
1434 menu->redraw = REDRAW_MOTION;
1437 case OP_MAIN_PREV_UNDELETED:
1441 if (menu->current < 1) {
1442 mutt_error (_("You are on the first message."));
1446 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1447 menu->current = menu->oldcurrent;
1448 if (menu->menu == MENU_MAIN)
1449 mutt_error (_("No undeleted messages."));
1451 else if (menu->menu == MENU_PAGER) {
1452 op = OP_DISPLAY_MESSAGE;
1456 menu->redraw = REDRAW_MOTION;
1463 if (menu->current < 1) {
1464 if (menu->menu == MENU_MAIN)
1465 mutt_error (_("You are on the first message."));
1470 if (menu->menu == MENU_PAGER) {
1471 op = OP_DISPLAY_MESSAGE;
1475 menu->redraw = REDRAW_MOTION;
1478 case OP_DECRYPT_COPY:
1479 case OP_DECRYPT_SAVE:
1480 case OP_COPY_MESSAGE:
1482 case OP_DECODE_COPY:
1483 case OP_DECODE_SAVE:
1486 if (mutt_save_message (tag ? NULL : CURHDR,
1487 (op == OP_DECRYPT_SAVE) ||
1488 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1489 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1490 (op == OP_DECRYPT_SAVE)
1491 || (op == OP_DECRYPT_COPY)
1492 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1499 menu->redraw |= REDRAW_INDEX;
1500 else if (option (OPTRESOLVE)) {
1501 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1502 menu->current = menu->oldcurrent;
1503 menu->redraw |= REDRAW_CURRENT;
1506 menu->redraw |= REDRAW_MOTION_RESYNCH;
1509 menu->redraw |= REDRAW_CURRENT;
1513 case OP_MAIN_NEXT_NEW:
1514 case OP_MAIN_NEXT_UNREAD:
1515 case OP_MAIN_PREV_NEW:
1516 case OP_MAIN_PREV_UNREAD:
1517 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1518 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1521 int first_unread = -1;
1529 for (j = 0; j != Context->vcount; j++) {
1530 #define CURHDRi Context->hdrs[Context->v2r[i]]
1531 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1532 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1534 if (i > Context->vcount - 1) {
1535 mutt_message _("Search wrapped to top.");
1543 mutt_message _("Search wrapped to bottom.");
1545 i = Context->vcount - 1;
1549 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1550 if (UNREAD (CURHDRi) && first_unread == -1)
1552 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1555 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1556 if (first_unread == -1)
1558 if ((!CURHDRi->old) && first_new == -1)
1562 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1565 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1566 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1567 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1572 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1573 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1574 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1576 menu->current = first_new;
1577 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1578 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1579 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1580 && first_unread != -1)
1581 menu->current = first_unread;
1583 if (menu->current == -1) {
1584 menu->current = menu->oldcurrent;
1585 mutt_error ("%s%s.",
1586 (op == OP_MAIN_NEXT_NEW
1588 OP_MAIN_PREV_NEW) ? _("No new messages") :
1589 _("No unread messages"),
1590 Context->pattern ? _(" in this limited view") : "");
1592 else if (menu->menu == MENU_PAGER) {
1593 op = OP_DISPLAY_MESSAGE;
1597 menu->redraw = REDRAW_MOTION;
1600 case OP_FLAG_MESSAGE:
1606 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1609 for (j = 0; j < Context->vcount; j++) {
1610 if (Context->hdrs[Context->v2r[j]]->tagged)
1611 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1612 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1615 menu->redraw |= REDRAW_INDEX;
1618 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1619 if (option (OPTRESOLVE)) {
1620 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1621 menu->current = menu->oldcurrent;
1622 menu->redraw = REDRAW_CURRENT;
1625 menu->redraw = REDRAW_MOTION_RESYNCH;
1628 menu->redraw = REDRAW_CURRENT;
1630 menu->redraw |= REDRAW_STATUS;
1639 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1642 for (j = 0; j < Context->vcount; j++) {
1643 if (Context->hdrs[Context->v2r[j]]->tagged) {
1644 if (Context->hdrs[Context->v2r[j]]->read ||
1645 Context->hdrs[Context->v2r[j]]->old)
1646 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1649 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1653 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1656 if (CURHDR->read || CURHDR->old)
1657 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1659 mutt_set_flag (Context, CURHDR, M_READ, 1);
1661 if (option (OPTRESOLVE)) {
1662 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1663 menu->current = menu->oldcurrent;
1664 menu->redraw = REDRAW_CURRENT;
1667 menu->redraw = REDRAW_MOTION_RESYNCH;
1670 menu->redraw = REDRAW_CURRENT;
1671 menu->redraw |= REDRAW_STATUS;
1675 case OP_TOGGLE_WRITE:
1678 if (mx_toggle_write (Context) == 0)
1679 menu->redraw |= REDRAW_STATUS;
1682 case OP_MAIN_NEXT_THREAD:
1683 case OP_MAIN_NEXT_SUBTHREAD:
1684 case OP_MAIN_PREV_THREAD:
1685 case OP_MAIN_PREV_SUBTHREAD:
1690 case OP_MAIN_NEXT_THREAD:
1691 menu->current = mutt_next_thread (CURHDR);
1694 case OP_MAIN_NEXT_SUBTHREAD:
1695 menu->current = mutt_next_subthread (CURHDR);
1698 case OP_MAIN_PREV_THREAD:
1699 menu->current = mutt_previous_thread (CURHDR);
1702 case OP_MAIN_PREV_SUBTHREAD:
1703 menu->current = mutt_previous_subthread (CURHDR);
1707 if (menu->current < 0) {
1708 menu->current = menu->oldcurrent;
1709 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1710 mutt_error (_("No more threads."));
1713 mutt_error (_("You are on the first thread."));
1715 else if (menu->menu == MENU_PAGER) {
1716 op = OP_DISPLAY_MESSAGE;
1720 menu->redraw = REDRAW_MOTION;
1723 case OP_MAIN_PARENT_MESSAGE:
1728 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1729 menu->current = menu->oldcurrent;
1731 else if (menu->menu == MENU_PAGER) {
1732 op = OP_DISPLAY_MESSAGE;
1736 menu->redraw = REDRAW_MOTION;
1739 case OP_MAIN_SET_FLAG:
1740 case OP_MAIN_CLEAR_FLAG:
1746 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0) {
1747 menu->redraw = REDRAW_STATUS;
1749 menu->redraw |= REDRAW_INDEX;
1750 else if (option (OPTRESOLVE)) {
1751 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1752 menu->current = menu->oldcurrent;
1753 menu->redraw |= REDRAW_CURRENT;
1756 menu->redraw |= REDRAW_MOTION_RESYNCH;
1759 menu->redraw |= REDRAW_CURRENT;
1763 case OP_MAIN_COLLAPSE_THREAD:
1767 if ((Sort & SORT_MASK) != SORT_THREADS) {
1768 mutt_error (_("Threading is not enabled."));
1773 if (CURHDR->collapsed) {
1774 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1775 mutt_set_virtual (Context);
1776 if (option (OPTUNCOLLAPSEJUMP))
1777 menu->current = mutt_thread_next_unread (Context, CURHDR);
1779 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1780 menu->current = mutt_collapse_thread (Context, CURHDR);
1781 mutt_set_virtual (Context);
1784 mutt_error (_("Thread contains unread messages."));
1789 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1793 case OP_MAIN_COLLAPSE_ALL:
1797 if ((Sort & SORT_MASK) != SORT_THREADS) {
1798 mutt_error (_("Threading is not enabled."));
1805 THREAD *thread, *top;
1808 if (CURHDR->collapsed)
1809 final = mutt_uncollapse_thread (Context, CURHDR);
1810 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1811 final = mutt_collapse_thread (Context, CURHDR);
1813 final = CURHDR->virtual;
1815 base = Context->hdrs[Context->v2r[final]];
1817 top = Context->tree;
1818 Context->collapsed = !Context->collapsed;
1819 while ((thread = top) != NULL) {
1820 while (!thread->message)
1821 thread = thread->child;
1822 h = thread->message;
1824 if (h->collapsed != Context->collapsed) {
1826 mutt_uncollapse_thread (Context, h);
1827 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1828 mutt_collapse_thread (Context, h);
1833 mutt_set_virtual (Context);
1834 for (j = 0; j < Context->vcount; j++) {
1835 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1841 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1845 /* --------------------------------------------------------------------
1846 * These functions are invoked directly from the internal-pager
1849 case OP_BOUNCE_MESSAGE:
1854 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1857 case OP_CREATE_ALIAS:
1859 mutt_create_alias (Context
1860 && Context->vcount ? CURHDR->env : NULL, NULL);
1861 MAYBE_REDRAW (menu->redraw);
1862 menu->redraw |= REDRAW_CURRENT;
1867 mutt_query_menu (NULL, 0);
1868 MAYBE_REDRAW (menu->redraw);
1871 case OP_PURGE_MESSAGE:
1878 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1881 mutt_tag_set_flag (M_DELETE, 1);
1882 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1883 if (option (OPTDELETEUNTAG))
1884 mutt_tag_set_flag (M_TAG, 0);
1885 menu->redraw = REDRAW_INDEX;
1888 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1889 mutt_set_flag (Context, CURHDR, M_PURGED,
1890 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1891 if (option (OPTDELETEUNTAG))
1892 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1893 if (option (OPTRESOLVE)) {
1894 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1895 menu->current = menu->oldcurrent;
1896 menu->redraw = REDRAW_CURRENT;
1898 else if (menu->menu == MENU_PAGER) {
1899 op = OP_DISPLAY_MESSAGE;
1903 menu->redraw |= REDRAW_MOTION_RESYNCH;
1906 menu->redraw = REDRAW_CURRENT;
1908 menu->redraw |= REDRAW_STATUS;
1911 case OP_DELETE_THREAD:
1912 case OP_DELETE_SUBTHREAD:
1918 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1920 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1921 op == OP_DELETE_THREAD ? 0 : 1);
1924 if (option (OPTDELETEUNTAG))
1925 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1926 op == OP_DELETE_THREAD ? 0 : 1);
1927 if (option (OPTRESOLVE))
1928 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1929 menu->current = menu->oldcurrent;
1930 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1936 if (Context && Context->magic == M_NNTP) {
1937 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1938 ((NNTP_DATA *) Context->data)->group))
1939 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1944 case OP_DISPLAY_ADDRESS:
1948 mutt_display_address (CURHDR->env);
1951 case OP_ENTER_COMMAND:
1953 CurrentMenu = MENU_MAIN;
1954 mutt_enter_command ();
1955 mutt_check_rescore (Context);
1956 if (option (OPTFORCEREDRAWINDEX))
1957 menu->redraw = REDRAW_FULL;
1958 unset_option (OPTFORCEREDRAWINDEX);
1959 unset_option (OPTFORCEREDRAWPAGER);
1962 case OP_EDIT_MESSAGE:
1969 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1971 if (option (OPTPGPAUTODEC)
1972 && (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1973 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1974 mutt_edit_message (Context, tag ? NULL : CURHDR);
1975 menu->redraw = REDRAW_FULL;
1979 case OP_FORWARD_MESSAGE:
1985 if (option (OPTPGPAUTODEC) &&
1986 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
1987 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1988 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
1989 menu->redraw = REDRAW_FULL;
1992 case OP_GROUP_REPLY:
1998 if (option (OPTPGPAUTODEC) &&
1999 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2000 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2002 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
2003 tag ? NULL : CURHDR);
2004 menu->redraw = REDRAW_FULL;
2013 if (option (OPTPGPAUTODEC) &&
2014 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2015 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2017 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
2018 tag ? NULL : CURHDR);
2019 menu->redraw = REDRAW_FULL;
2025 ci_send_message (0, NULL, NULL, Context, NULL);
2026 menu->redraw = REDRAW_FULL;
2029 case OP_EXTRACT_KEYS:
2032 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
2033 menu->redraw = REDRAW_FULL;
2037 case OP_CHECK_TRADITIONAL:
2040 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2041 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2043 if (menu->menu == MENU_PAGER) {
2044 op = OP_DISPLAY_MESSAGE;
2053 mutt_pipe_message (tag ? NULL : CURHDR);
2054 /* in an IMAP folder index with imap_peek=no, piping could change
2055 * * new or old messages status to read. Redraw what's needed.
2057 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2058 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2060 MAYBE_REDRAW (menu->redraw);
2067 mutt_print_message (tag ? NULL : CURHDR);
2068 /* in an IMAP folder index with imap_peek=no, piping could change
2069 * * new or old messages status to read. Redraw what's needed.
2071 if (Context->magic == M_IMAP && !option (OPTIMAPPEEK)) {
2072 menu->redraw = (tag ? REDRAW_INDEX : REDRAW_CURRENT) | REDRAW_STATUS;
2076 case OP_MAIN_READ_THREAD:
2077 case OP_MAIN_READ_SUBTHREAD:
2083 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2085 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2086 op == OP_MAIN_READ_THREAD ? 0 : 1);
2089 if (option (OPTRESOLVE)) {
2090 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2091 mutt_next_thread (CURHDR) :
2092 mutt_next_subthread (CURHDR))) == -1)
2093 menu->current = menu->oldcurrent;
2095 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2099 case OP_RECALL_MESSAGE:
2102 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2103 menu->redraw = REDRAW_FULL;
2113 for (j = 0; j < Context->vcount; j++) {
2114 if (Context->hdrs[Context->v2r[j]]->tagged)
2115 mutt_resend_message (NULL, Context,
2116 Context->hdrs[Context->v2r[j]]);
2120 mutt_resend_message (NULL, Context, CURHDR);
2122 menu->redraw = REDRAW_FULL;
2128 case OP_FORWARD_TO_GROUP:
2131 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2132 Context && Context->msgcount == 0) {
2133 mutt_error (_("There are no messages."));
2136 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2137 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2138 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2139 _("Reply by mail as poster prefers?")) !=
2141 if (Context && Context->magic == M_NNTP
2142 && !((NNTP_DATA *) Context->data)->allowed
2143 && query_quadoption (OPT_TOMODERATED,
2145 ("Posting to this group not allowed, may be moderated. Continue?"))
2149 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2152 if (op == OP_FOLLOWUP)
2153 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2154 tag ? NULL : CURHDR);
2156 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2157 tag ? NULL : CURHDR);
2159 menu->redraw = REDRAW_FULL;
2170 if (option (OPTPGPAUTODEC) &&
2171 (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED)))
2172 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2174 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2175 menu->redraw = REDRAW_FULL;
2178 case OP_SHELL_ESCAPE:
2180 mutt_shell_escape ();
2181 MAYBE_REDRAW (menu->redraw);
2185 case OP_TAG_SUBTHREAD:
2189 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2190 op == OP_TAG_THREAD ? 0 : 1);
2193 if (option (OPTRESOLVE)) {
2194 menu->current = mutt_next_thread (CURHDR);
2196 if (menu->current == -1)
2197 menu->current = menu->oldcurrent;
2199 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2209 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2212 mutt_tag_set_flag (M_DELETE, 0);
2213 mutt_tag_set_flag (M_PURGED, 0);
2214 menu->redraw = REDRAW_INDEX;
2217 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2218 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2219 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2221 menu->redraw = REDRAW_MOTION_RESYNCH;
2224 menu->redraw = REDRAW_CURRENT;
2226 menu->redraw |= REDRAW_STATUS;
2229 case OP_UNDELETE_THREAD:
2230 case OP_UNDELETE_SUBTHREAD:
2236 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2238 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2239 op == OP_UNDELETE_THREAD ? 0 : 1)
2240 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2241 op == OP_UNDELETE_THREAD ? 0 : 1);
2244 if (option (OPTRESOLVE)) {
2245 if (op == OP_UNDELETE_THREAD)
2246 menu->current = mutt_next_thread (CURHDR);
2248 menu->current = mutt_next_subthread (CURHDR);
2250 if (menu->current == -1)
2251 menu->current = menu->oldcurrent;
2253 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2262 if (option (OPTFORCEBUFFYCHECK))
2265 menu->redraw = REDRAW_FULL;
2268 case OP_VIEW_ATTACHMENTS:
2271 mutt_view_attachments (CURHDR);
2272 if (CURHDR->attach_del)
2273 Context->changed = 1;
2274 menu->redraw = REDRAW_FULL;
2284 case OP_SIDEBAR_SCROLL_UP:
2285 case OP_SIDEBAR_SCROLL_DOWN:
2286 case OP_SIDEBAR_NEXT:
2287 case OP_SIDEBAR_PREV:
2288 case OP_SIDEBAR_NEXT_NEW:
2289 case OP_SIDEBAR_PREV_NEW:
2290 sidebar_scroll (op);
2293 if (menu->menu == MENU_MAIN)
2294 km_error_key (MENU_MAIN);
2297 if (menu->menu == MENU_PAGER) {
2298 menu->menu = MENU_MAIN;
2299 menu->redraw = REDRAW_FULL;
2307 /* Close all open IMAP connections */
2310 /* Close all open NNTP connections */
2315 mutt_menuDestroy (&menu);
2319 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2326 for (color = ColorIndexList; color; color = color->next)
2327 if (mutt_pattern_exec
2328 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2329 curhdr->pair = color->pair;
2332 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];