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-ui/lib-ui.h>
15 #include <lib-ui/sidebar.h>
16 #include <lib-mx/mx.h>
26 #include "recvattach.h"
31 #include <imap/imap_private.h>
37 static const char *No_mailbox_is_open = N_("No mailbox is open.");
38 static const char *There_are_no_messages = N_("There are no messages.");
39 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
40 static const char *Function_not_permitted_in_attach_message_mode =
41 N_("Function not permitted in attach-message mode.");
42 static const char *No_visible = N_("No visible messages.");
44 #define CHECK_IN_MAILBOX if (!Context) \
47 mutt_error (_(No_mailbox_is_open)); \
51 #define CHECK_MSGCOUNT if (!Context) \
54 mutt_error(_(No_mailbox_is_open)); \
57 else if (!Context->msgcount) \
60 mutt_error(_(There_are_no_messages)); \
64 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
67 mutt_error(_(No_visible)); \
72 #define CHECK_READONLY if (Context->readonly) \
75 mutt_error(_(Mailbox_is_read_only)); \
79 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
82 mutt_error(_(Function_not_permitted_in_attach_message_mode)); \
86 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
87 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
88 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
89 #define SW (option(OPTMBOXPANE)?SidebarWidth:0)
91 extern size_t UngetCount;
93 void index_make_entry (char *s, ssize_t l, struct menu_t * menu, int num)
95 format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_INDEX;
96 int edgemsgno, reverse = Sort & SORT_REVERSE;
97 HEADER *h = Context->hdrs[Context->v2r[num]];
100 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
101 flag |= M_FORMAT_TREE; /* display the thread tree */
102 if (h->display_subject)
103 flag |= M_FORMAT_FORCESUBJ;
106 if (menu->top + menu->pagelen > menu->max)
107 edgemsgno = Context->v2r[menu->max - 1];
109 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
112 edgemsgno = Context->v2r[menu->top];
114 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
118 /* if no ancestor is visible on current screen, provisionally force
120 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
122 flag |= M_FORMAT_FORCESUBJ;
125 else if (tmp->message->virtual >= 0)
128 if (flag & M_FORMAT_FORCESUBJ) {
129 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
133 /* ...but if a previous sibling is available, don't force it */
134 if (reverse ? tmp->message->msgno >
135 edgemsgno : tmp->message->msgno < edgemsgno)
137 else if (tmp->message->virtual >= 0) {
138 flag &= ~M_FORMAT_FORCESUBJ;
146 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
149 int index_color (int index_no)
151 HEADER *h = Context->hdrs[Context->v2r[index_no]];
156 mutt_set_header_color (Context, h);
160 static int ci_next_undeleted (int msgno)
164 for (i = msgno + 1; i < Context->vcount; i++)
165 if (!Context->hdrs[Context->v2r[i]]->deleted)
170 static int ci_previous_undeleted (int msgno)
174 for (i = msgno - 1; i >= 0; i--)
175 if (!Context->hdrs[Context->v2r[i]]->deleted)
180 /* Return the index of the first new message, or failing that, the first
183 static int ci_first_message (void)
187 if (Context && Context->msgcount) {
188 for (i = 0; i < Context->vcount; i++) {
189 if (!Context->hdrs[Context->v2r[i]]->read &&
190 !Context->hdrs[Context->v2r[i]]->deleted) {
191 if (!Context->hdrs[Context->v2r[i]]->old)
200 /* If Sort is reverse and not threaded, the latest message is first.
201 * If Sort is threaded, the latest message is first iff exactly one
202 * of Sort and SortAux are reverse.
204 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
205 ((Sort & SORT_MASK) == SORT_THREADS &&
206 ((Sort ^ SortAux) & SORT_REVERSE)))
209 return (Context->vcount ? Context->vcount - 1 : 0);
214 /* This should be in mx.c, but it only gets used here. */
215 static int mx_toggle_write (CONTEXT * ctx)
221 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
226 if (ctx->dontwrite) {
228 mutt_message (_("Changes to folder will be written on folder exit."));
232 mutt_message (_("Changes to folder will not be written."));
238 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
239 int oldcount, int index_hint)
241 /* store pointers to the newly added messages */
242 HEADER **save_new = NULL;
245 /* take note of the current message */
247 if (menu->current < Context->vcount)
248 menu->oldcurrent = index_hint;
250 oldcount = 0; /* invalid message number! */
253 /* We are in a limited view. Check if the new message(s) satisfy
254 * the limit criteria. If they do, set their virtual msgno so that
255 * they will be visible in the limited view */
256 if (Context->pattern) {
257 #define THIS_BODY Context->hdrs[j]->content
258 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
259 if (mutt_pattern_exec
260 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
262 Context->hdrs[j]->virtual = Context->vcount;
263 Context->v2r[Context->vcount] = j;
264 Context->hdrs[j]->limited = 1;
267 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
273 /* save the list of new messages */
274 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
275 save_new = p_new(HEADER*, Context->msgcount - oldcount);
276 for (j = oldcount; j < Context->msgcount; j++)
277 save_new[j - oldcount] = Context->hdrs[j];
280 /* if the mailbox was reopened, need to rethread from scratch */
281 mutt_sort_headers (Context, (check == M_REOPENED));
283 /* uncollapse threads with new mail */
284 if ((Sort & SORT_MASK) == SORT_THREADS) {
285 if (check == M_REOPENED) {
288 Context->collapsed = 0;
290 for (h = Context->tree; h; h = h->next) {
291 for (c = h; !c->message; c = c->child);
292 mutt_uncollapse_thread (Context, c->message);
294 mutt_set_virtual (Context);
297 for (j = 0; j < Context->msgcount - oldcount; j++) {
300 for (k = 0; k < Context->msgcount; k++) {
301 HEADER *h = Context->hdrs[k];
303 if (h == save_new[j] && (!Context->pattern || h->limited))
304 mutt_uncollapse_thread (Context, h);
308 mutt_set_virtual (Context);
314 /* restore the current message to the message it was pointing to */
315 for (j = 0; j < Context->vcount; j++) {
316 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
323 if (menu->current < 0)
324 menu->current = ci_first_message ();
327 static void resort_index (MUTTMENU * menu)
330 HEADER *current = CURHDR;
333 mutt_sort_headers (Context, 0);
334 /* Restore the current message */
336 for (i = 0; i < Context->vcount; i++) {
337 if (Context->hdrs[Context->v2r[i]] == current) {
343 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
344 menu->current = mutt_parent_message (Context, current);
346 if (menu->current < 0)
347 menu->current = ci_first_message ();
349 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
352 /* This function handles the message index window as well as commands returned
353 * from the pager (MENU_PAGER).
355 int mutt_index_menu (void)
357 char buf[LONG_STRING];
360 int done = 0; /* controls when to exit the "event" loop */
362 int tag = 0; /* has the tag-prefix command been pressed? */
367 const char *cp; /* temporary variable. */
368 int index_hint; /* used to restore cursor position */
369 int do_buffy_notify = 1;
370 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
371 int attach_msg = option (OPTATTACHMSG);
373 menu = mutt_new_menu ();
374 menu->menu = MENU_MAIN;
376 menu->pagelen = LINES - 3;
377 menu->make_entry = (void *) index_make_entry;
378 menu->color = index_color;
379 menu->current = ci_first_message ();
382 buffy_check (0); /* force the buffy check after we enter the folder */
383 /* record folder we open to place sidebar indicator properly */
384 if (Context && Context->path)
385 sidebar_set_current (Context->path);
389 tag = 0; /* clear the tag-prefix */
391 menu->max = Context ? Context->vcount : 0;
392 oldcount = Context ? Context->msgcount : 0;
394 /* check if we need to resort the index because just about
395 * any 'op' below could do mutt_enter_command(), either here or
396 * from any new menu launched, and change $sort/$sort_aux
398 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
401 if (option (OPTREDRAWTREE) && Context && Context->msgcount
402 && (Sort & SORT_MASK) == SORT_THREADS) {
403 mutt_draw_tree (Context);
404 menu->redraw |= REDRAW_STATUS;
405 unset_option (OPTREDRAWTREE);
408 if (Context && !attach_msg) {
411 /* check for new mail in the mailbox. If nonzero, then something has
412 * changed about the file (either we got new mail or the file was
413 * modified underneath us.)
416 imap_allow_reopen (Context);
418 index_hint = (Context->vcount && menu->current >= 0
419 && menu->current < Context->vcount) ? CURHDR->index : 0;
421 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
422 if (!Context->path) {
423 /* fatal error occurred */
425 menu->redraw = REDRAW_FULL;
427 set_option (OPTSEARCHINVALID);
429 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
430 update_index (menu, Context, check, oldcount, index_hint);
432 /* notify the user of new mail */
433 if (check == M_REOPENED)
435 ("Mailbox was externally modified. Flags may be wrong."));
436 else if (check == M_NEW_MAIL) {
437 /* on new mail: redraw sidebar */
439 mutt_message (_("New mail in this mailbox."));
441 if (mod_core.beep_new)
444 else if (check == M_FLAGS)
445 mutt_message (_("Mailbox was externally modified."));
447 /* avoid the message being overwritten by buffy */
450 menu->redraw = REDRAW_FULL;
451 menu->max = Context->vcount;
453 set_option (OPTSEARCHINVALID);
458 imap_disallow_reopen (Context);
461 /* check for new mail in the incoming folders */
463 if ((newcount = buffy_check (0)) != oldcount) {
464 menu->redraw |= REDRAW_STATUS;
465 menu->redraw |= REDRAW_SIDEBAR;
467 if (do_buffy_notify) {
468 if (buffy_notify () && mod_core.beep_new)
477 if (menu->redraw & REDRAW_SIDEBAR)
479 if (menu->redraw & REDRAW_FULL) {
480 menu_redraw_full (menu);
485 if (menu->menu == MENU_MAIN) {
486 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
487 menu_check_recenter (menu);
489 if (menu->redraw & REDRAW_INDEX) {
490 menu_redraw_index (menu);
491 menu->redraw |= REDRAW_STATUS;
493 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
494 menu_redraw_motion (menu);
495 else if (menu->redraw & REDRAW_CURRENT)
496 menu_redraw_current (menu);
499 if (menu->redraw & REDRAW_STATUS) {
500 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
501 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
502 sidebar_draw_frames();
503 SETCOLOR (MT_COLOR_STATUS);
504 BKGDSET (MT_COLOR_STATUS);
505 wmove(stdscr, option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
506 mutt_paddstr (COLS-SW, buf);
507 SETCOLOR (MT_COLOR_NORMAL);
508 BKGDSET (MT_COLOR_NORMAL);
509 sidebar_set_buffystats (Context);
510 menu->redraw &= ~REDRAW_STATUS;
511 if (option (OPTXTERMSETTITLES)) {
512 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermTitle));
513 printf("\033]2;%s\007", buf);
514 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermIcon));
515 printf("\033]1;%s\007", buf);
521 if (menu->current < menu->max)
522 menu->oldcurrent = menu->current;
524 menu->oldcurrent = -1;
526 if (option (OPTBRAILLEFRIENDLY))
527 wmove (stdscr, menu->current - menu->top + menu->offset, 0);
529 wmove (stdscr, menu->current - menu->top + menu->offset, COLS - 1);
534 mutt_resize_screen ();
535 menu->redraw = REDRAW_FULL;
536 menu->menu = MENU_MAIN;
538 menu->top = 0; /* so we scroll the right amount */
540 * force a real complete redraw. wclrtobot(stdscr) doesn't seem to be able
541 * to handle every case without this.
543 clearok (stdscr, TRUE);
547 op = km_dokey (MENU_MAIN);
549 continue; /* either user abort or timeout */
553 /* special handling for the tag-prefix function */
554 if (op == OP_TAG_PREFIX) {
556 mutt_error (_("No mailbox is open."));
561 if (!Context->tagged) {
562 mutt_error (_("No tagged messages."));
568 /* give visual indication that the next command is a tag- command */
569 mvwaddstr (stdscr, LINES - 1, 0, "tag-");
572 /* get the real command */
573 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
574 /* abort tag sequence */
575 CLEARLINE (LINES - 1);
579 else if (option (OPTAUTOTAG) && Context && Context->tagged)
582 if (op == OP_TAG_PREFIX_COND) {
584 mutt_error (_("No mailbox is open."));
589 if (!Context->tagged) {
592 while (UngetCount > 0) {
594 if (tmp.op == OP_END_COND)
597 mutt_message (_("Nothing to do."));
603 /* give visual indication that the next command is a tag- command */
604 mvwaddstr (stdscr, LINES - 1, 0, "tag-");
607 /* get the real command */
608 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
609 /* abort tag sequence */
610 CLEARLINE (LINES - 1);
618 if (menu->current < menu->max)
619 menu->oldcurrent = menu->current;
621 menu->oldcurrent = -1;
623 mutt_curs_set (1); /* fallback from the pager */
627 unset_option (OPTNEWS); /* for any case */
632 /* ----------------------------------------------------------------------
637 menu_bottom_page (menu);
640 menu_first_entry (menu);
643 menu_middle_page (menu);
649 menu_half_down (menu);
652 menu_next_line (menu);
655 menu_prev_line (menu);
658 menu_next_page (menu);
661 menu_prev_page (menu);
664 menu_last_entry (menu);
667 menu_top_page (menu);
670 menu_current_top (menu);
672 case OP_CURRENT_MIDDLE:
673 menu_current_middle (menu);
675 case OP_CURRENT_BOTTOM:
676 menu_current_bottom (menu);
683 if (Context->magic == M_NNTP) {
686 if (op == OP_GET_MESSAGE) {
688 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
693 string_list_t *ref = CURHDR->env->references;
696 mutt_error (_("Article has no parent reference!"));
700 m_strcpy(buf, sizeof(buf), ref->data);
702 if (!Context->id_hash)
703 Context->id_hash = mutt_make_id_hash (Context);
704 if ((h = hash_find (Context->id_hash, buf))) {
705 if (h->virtual != -1) {
706 menu->current = h->virtual;
707 menu->redraw = REDRAW_MOTION_RESYNCH;
709 else if (h->collapsed) {
710 mutt_uncollapse_thread (Context, h);
711 mutt_set_virtual (Context);
712 menu->current = h->virtual;
713 menu->redraw = REDRAW_MOTION_RESYNCH;
716 mutt_error (_("Message not visible in limited view."));
719 if (nntp_check_msgid (Context, buf) == 0) {
720 h = Context->hdrs[Context->msgcount - 1];
721 mutt_sort_headers (Context, 0);
722 menu->current = h->virtual;
723 menu->redraw = REDRAW_FULL;
726 mutt_error (_("Article %s not found on server"), buf);
731 case OP_GET_CHILDREN:
732 case OP_RECONSTRUCT_THREAD:
734 if (Context->magic == M_NNTP) {
736 int old = CURHDR->index;
738 if (!CURHDR->env->message_id) {
739 mutt_error (_("No Message-ID. Unable to perform operation"));
744 if (!Context->id_hash)
745 Context->id_hash = mutt_make_id_hash (Context);
746 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
748 if (op == OP_RECONSTRUCT_THREAD) {
749 string_list_t *ref = CURHDR->env->references;
752 nntp_check_msgid (Context, ref->data);
753 /* the last msgid in References is the root message */
755 m_strcpy(buf, sizeof(buf), ref->data);
759 mutt_message (_("Check for children of message..."));
761 if (nntp_check_children (Context, buf) == 0) {
762 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
763 h = hash_find (Context->id_hash, buf);
764 /* if the root message was retrieved, move to it */
766 menu->current = h->virtual;
767 else /* try to restore old position */
768 for (i = 0; i < Context->msgcount; i++)
769 if (Context->hdrs[i]->index == old) {
770 menu->current = Context->hdrs[i]->virtual;
771 /* As an added courtesy, recenter the menu
772 * with the current entry at the middle of the screen */
773 menu_check_recenter (menu);
774 menu_current_middle (menu);
777 menu->redraw = REDRAW_FULL;
787 if (isdigit (LastKey))
788 mutt_ungetch (LastKey, 0);
790 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
794 if (!isdigit ((unsigned char) buf[0])) {
795 mutt_error (_("Argument must be a message number."));
801 if (i > 0 && i <= Context->msgcount) {
802 for (j = i - 1; j < Context->msgcount; j++) {
803 if (Context->hdrs[j]->virtual != -1)
806 if (j >= Context->msgcount) {
807 for (j = i - 2; j >= 0; j--) {
808 if (Context->hdrs[j]->virtual != -1)
814 menu->current = Context->hdrs[j]->virtual;
815 if (menu->menu == MENU_PAGER) {
816 op = OP_DISPLAY_MESSAGE;
820 menu->redraw = REDRAW_MOTION;
823 mutt_error (_("That message is not visible."));
826 mutt_error (_("Invalid message number."));
830 /* --------------------------------------------------------------------
831 * `index' specific commands
834 case OP_MAIN_DELETE_PATTERN:
840 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
843 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
844 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
847 case OP_MAIN_FETCH_MAIL:
851 menu->redraw = REDRAW_FULL;
856 mutt_help (MENU_MAIN);
857 menu->redraw = REDRAW_FULL;
860 case OP_MAIN_SHOW_LIMIT:
862 if (!Context->pattern)
863 mutt_message (_("No limit pattern is in effect."));
868 /* i18n: ask for a limit to apply */
869 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
870 mutt_message ("%s", buffer);
878 menu->oldcurrent = (Context->vcount && menu->current >= 0
880 Context->vcount) ? CURHDR->index : -1;
881 if (op == OP_TOGGLE_READ) {
882 char buffer[LONG_STRING];
884 if (m_strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
885 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
886 Context->pattern ? Context->pattern : ".*");
887 set_option (OPTHIDEREAD);
890 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
891 if (m_strncmp (buf, ".*", 2) == 0)
892 snprintf (buf, sizeof (buf), "~A");
893 unset_option (OPTHIDEREAD);
895 p_delete(&Context->pattern);
896 Context->pattern = m_strdup(buf);
898 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
899 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
901 if (menu->oldcurrent >= 0) {
902 /* try to find what used to be the current message */
904 for (i = 0; i < Context->vcount; i++)
905 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
909 if (menu->current < 0)
914 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
915 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
916 mutt_draw_tree (Context);
917 menu->redraw = REDRAW_FULL;
919 if (Context->pattern)
920 mutt_message _("To view all messages, limit to \"all\".");
931 if (query_quadoption2(mod_core.quit, _("Quit Madmutt?")) == M_YES) {
934 oldcount = Context ? Context->msgcount : 0;
937 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
940 if (check == M_NEW_MAIL || check == M_REOPENED)
941 update_index (menu, Context, check, oldcount, index_hint);
943 menu->redraw = REDRAW_FULL; /* new mail arrived? */
944 set_option (OPTSEARCHINVALID);
951 clearok (stdscr, TRUE);
952 menu->redraw = REDRAW_FULL;
956 case OP_SEARCH_REVERSE:
958 case OP_SEARCH_OPPOSITE:
962 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
963 menu->current = menu->oldcurrent;
965 menu->redraw = REDRAW_MOTION;
969 case OP_SORT_REVERSE:
971 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
972 if (Context && Context->msgcount) {
974 set_option (OPTSEARCHINVALID);
983 if (tag && !option (OPTAUTOTAG)) {
984 for (j = 0; j < Context->vcount; j++)
985 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
986 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
989 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
990 Context->last_tag = CURHDR->tagged ? CURHDR :
991 ((Context->last_tag == CURHDR && !CURHDR->tagged)
992 ? NULL : Context->last_tag);
993 menu->redraw = REDRAW_STATUS;
994 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
996 menu->redraw |= REDRAW_MOTION_RESYNCH;
999 menu->redraw |= REDRAW_CURRENT;
1003 case OP_MAIN_TAG_PATTERN:
1007 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1008 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1011 case OP_MAIN_UNDELETE_PATTERN:
1017 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1019 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1021 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1024 case OP_MAIN_UNTAG_PATTERN:
1028 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1029 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1032 /* --------------------------------------------------------------------
1033 * The following operations can be performed inside of the pager.
1036 case OP_MAIN_IMAP_FETCH:
1037 if (Context->magic == M_IMAP)
1038 imap_check_mailbox (Context, &index_hint, 1);
1041 case OP_MAIN_SYNC_FOLDER:
1043 if (Context && !Context->msgcount)
1050 int oldvcount = Context->vcount;
1051 oldcount = Context->msgcount;
1055 /* calculate the number of messages _above_ the cursor,
1056 * so we can keep the cursor on the current message
1058 for (j = 0; j <= menu->current; j++) {
1059 if (Context->hdrs[Context->v2r[j]]->deleted)
1063 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1064 if (Context->vcount != oldvcount)
1065 menu->current -= dcount;
1066 set_option (OPTSEARCHINVALID);
1068 else if (check == M_NEW_MAIL || check == M_REOPENED)
1069 update_index (menu, Context, check, oldcount, index_hint);
1072 * do a sanity check even if mx_sync_mailbox failed.
1075 if (menu->current < 0 || menu->current >= Context->vcount)
1076 menu->current = ci_first_message ();
1079 /* check for a fatal error, or all messages deleted */
1083 /* if we were in the pager, redisplay the message */
1084 if (menu->menu == MENU_PAGER) {
1085 op = OP_DISPLAY_MESSAGE;
1089 menu->redraw = REDRAW_FULL;
1092 case OP_SIDEBAR_OPEN:
1093 case OP_MAIN_CHANGE_FOLDER:
1094 case OP_MAIN_CHANGE_FOLDER_READONLY:
1096 case OP_MAIN_CHANGE_GROUP:
1097 case OP_MAIN_CHANGE_GROUP_READONLY:
1099 if (attach_msg || option (OPTREADONLY) ||
1101 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1103 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1109 cp = _("Open mailbox in read-only mode");
1111 cp = _("Open mailbox");
1115 unset_option (OPTNEWS);
1116 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1117 set_option (OPTNEWS);
1118 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1121 cp = _("Open newsgroup in read-only mode");
1123 cp = _("Open newsgroup");
1124 nntp_buffy (buf, sizeof (buf));
1129 if (Context && Context->path)
1130 m_strcpy(buf, sizeof(buf), Context->path);
1131 if (op != OP_SIDEBAR_OPEN)
1132 buffy_next (buf, sizeof (buf));
1135 if (op == OP_SIDEBAR_OPEN) {
1136 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1138 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1139 if (menu->menu == MENU_PAGER) {
1140 op = OP_DISPLAY_MESSAGE;
1146 CLEARLINE (LINES - 1);
1151 if (option (OPTNEWS)) {
1152 unset_option (OPTNEWS);
1153 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1157 mutt_expand_path (buf, sizeof (buf));
1158 if (mx_get_magic (buf) <= 0) {
1159 mutt_error (_("%s is not a mailbox."), buf);
1162 m_strreplace(&CurrentFolder, buf);
1167 if (Context->cinfo && Context->realpath)
1168 m_strreplace(&LastFolder, Context->realpath);
1170 m_strreplace(&LastFolder, Context->path);
1171 oldcount = Context ? Context->msgcount : 0;
1173 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1174 if (check == M_NEW_MAIL || check == M_REOPENED)
1175 update_index (menu, Context, check, oldcount, index_hint);
1177 set_option (OPTSEARCHINVALID);
1178 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1186 /* Set CurrentMenu to MENU_MAIN before executing any folder
1187 * hooks so that all the index menu functions are available to
1191 CurrentMenu = MENU_MAIN;
1192 mutt_folder_hook (buf);
1194 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1195 menu->current = ci_first_message ();
1199 sidebar_set_current (buf);
1201 mutt_clear_error ();
1202 buffy_check (0); /* force the buffy check after we have changed
1204 menu->redraw = REDRAW_FULL;
1205 set_option (OPTSEARCHINVALID);
1208 case OP_DISPLAY_MESSAGE:
1209 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1214 * toggle the weeding of headers so that a user can press the key
1215 * again while reading the message.
1217 if (op == OP_DISPLAY_HEADERS)
1218 toggle_option (OPTWEED);
1220 unset_option (OPTNEEDRESORT);
1222 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1223 mutt_uncollapse_thread (Context, CURHDR);
1224 mutt_set_virtual (Context);
1225 if (option (OPTUNCOLLAPSEJUMP))
1226 menu->current = mutt_thread_next_unread (Context, CURHDR);
1229 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1230 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1232 if ((op = mutt_display_message (CURHDR)) == -1) {
1233 unset_option (OPTNEEDRESORT);
1237 menu->menu = MENU_PAGER;
1238 menu->oldcurrent = menu->current;
1244 if (menu->menu == MENU_MAIN && attach_msg) {
1249 if ((menu->menu == MENU_MAIN)
1250 && (query_quadoption2(mod_core.quit,
1251 _("Exit Madmutt without saving?")) == M_YES))
1254 mx_fastclose_mailbox (Context);
1266 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1267 /* if we were in the pager, redisplay the message */
1268 if (menu->menu == MENU_PAGER) {
1269 op = OP_DISPLAY_MESSAGE;
1273 menu->redraw = REDRAW_CURRENT;
1276 case OP_MAIN_BREAK_THREAD:
1282 if ((Sort & SORT_MASK) != SORT_THREADS)
1283 mutt_error (_("Threading is not enabled."));
1287 HEADER *oldcur = CURHDR;
1289 mutt_break_thread (CURHDR);
1290 mutt_sort_headers (Context, 1);
1291 menu->current = oldcur->virtual;
1294 Context->changed = 1;
1295 mutt_message _("Thread broken");
1297 if (menu->menu == MENU_PAGER) {
1298 op = OP_DISPLAY_MESSAGE;
1302 menu->redraw |= REDRAW_INDEX;
1306 case OP_MAIN_LINK_THREADS:
1312 if ((Sort & SORT_MASK) != SORT_THREADS)
1313 mutt_error (_("Threading is not enabled."));
1315 else if (!CURHDR->env->message_id)
1316 mutt_error (_("No Message-ID: header available to link thread"));
1318 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1319 mutt_error (_("First, please tag a message to be linked here"));
1322 HEADER *oldcur = CURHDR;
1324 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1326 mutt_sort_headers (Context, 1);
1327 menu->current = oldcur->virtual;
1329 Context->changed = 1;
1330 mutt_message _("Threads linked");
1333 mutt_error (_("No thread linked"));
1336 if (menu->menu == MENU_PAGER) {
1337 op = OP_DISPLAY_MESSAGE;
1341 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1344 case OP_MAIN_NEXT_UNDELETED:
1348 if (menu->current >= Context->vcount - 1) {
1349 if (menu->menu == MENU_MAIN)
1350 mutt_error (_("You are on the last message."));
1354 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1355 menu->current = menu->oldcurrent;
1356 if (menu->menu == MENU_MAIN)
1357 mutt_error (_("No undeleted messages."));
1359 else if (menu->menu == MENU_PAGER) {
1360 op = OP_DISPLAY_MESSAGE;
1364 menu->redraw = REDRAW_MOTION;
1371 if (menu->current >= Context->vcount - 1) {
1372 if (menu->menu == MENU_MAIN)
1373 mutt_error (_("You are on the last message."));
1378 if (menu->menu == MENU_PAGER) {
1379 op = OP_DISPLAY_MESSAGE;
1383 menu->redraw = REDRAW_MOTION;
1386 case OP_MAIN_PREV_UNDELETED:
1390 if (menu->current < 1) {
1391 mutt_error (_("You are on the first message."));
1395 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1396 menu->current = menu->oldcurrent;
1397 if (menu->menu == MENU_MAIN)
1398 mutt_error (_("No undeleted messages."));
1400 else if (menu->menu == MENU_PAGER) {
1401 op = OP_DISPLAY_MESSAGE;
1405 menu->redraw = REDRAW_MOTION;
1412 if (menu->current < 1) {
1413 if (menu->menu == MENU_MAIN)
1414 mutt_error (_("You are on the first message."));
1419 if (menu->menu == MENU_PAGER) {
1420 op = OP_DISPLAY_MESSAGE;
1424 menu->redraw = REDRAW_MOTION;
1427 case OP_DECRYPT_COPY:
1428 case OP_DECRYPT_SAVE:
1429 case OP_COPY_MESSAGE:
1431 case OP_DECODE_COPY:
1432 case OP_DECODE_SAVE:
1435 if (mutt_save_message (tag ? NULL : CURHDR,
1436 (op == OP_DECRYPT_SAVE) ||
1437 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1438 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1439 (op == OP_DECRYPT_SAVE)
1440 || (op == OP_DECRYPT_COPY)
1441 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1448 menu->redraw |= REDRAW_INDEX;
1449 else if (option (OPTRESOLVE)) {
1450 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1451 menu->current = menu->oldcurrent;
1452 menu->redraw |= REDRAW_CURRENT;
1455 menu->redraw |= REDRAW_MOTION_RESYNCH;
1458 menu->redraw |= REDRAW_CURRENT;
1462 case OP_MAIN_NEXT_NEW:
1463 case OP_MAIN_NEXT_UNREAD:
1464 case OP_MAIN_PREV_NEW:
1465 case OP_MAIN_PREV_UNREAD:
1466 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1467 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1470 int first_unread = -1;
1478 for (j = 0; j != Context->vcount; j++) {
1479 #define CURHDRi Context->hdrs[Context->v2r[i]]
1480 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1481 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1483 if (i > Context->vcount - 1) {
1484 mutt_message _("Search wrapped to top.");
1492 mutt_message _("Search wrapped to bottom.");
1494 i = Context->vcount - 1;
1498 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1499 if (UNREAD (CURHDRi) && first_unread == -1)
1501 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1504 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1505 if (first_unread == -1)
1507 if ((!CURHDRi->old) && first_new == -1)
1511 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1514 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1515 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1516 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1521 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1522 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1523 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1525 menu->current = first_new;
1526 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1527 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1528 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1529 && first_unread != -1)
1530 menu->current = first_unread;
1532 if (menu->current == -1) {
1533 menu->current = menu->oldcurrent;
1534 mutt_error ("%s%s.",
1535 (op == OP_MAIN_NEXT_NEW
1537 OP_MAIN_PREV_NEW) ? _("No new messages") :
1538 _("No unread messages"),
1539 Context->pattern ? _(" in this limited view") : "");
1541 else if (menu->menu == MENU_PAGER) {
1542 op = OP_DISPLAY_MESSAGE;
1546 menu->redraw = REDRAW_MOTION;
1549 case OP_FLAG_MESSAGE:
1555 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1558 for (j = 0; j < Context->vcount; j++) {
1559 if (Context->hdrs[Context->v2r[j]]->tagged)
1560 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1561 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1564 menu->redraw |= REDRAW_INDEX;
1567 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1568 if (option (OPTRESOLVE)) {
1569 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1570 menu->current = menu->oldcurrent;
1571 menu->redraw = REDRAW_CURRENT;
1574 menu->redraw = REDRAW_MOTION_RESYNCH;
1577 menu->redraw = REDRAW_CURRENT;
1579 menu->redraw |= REDRAW_STATUS;
1588 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1591 for (j = 0; j < Context->vcount; j++) {
1592 if (Context->hdrs[Context->v2r[j]]->tagged) {
1593 if (Context->hdrs[Context->v2r[j]]->read ||
1594 Context->hdrs[Context->v2r[j]]->old)
1595 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1598 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1602 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1605 if (CURHDR->read || CURHDR->old)
1606 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1608 mutt_set_flag (Context, CURHDR, M_READ, 1);
1610 if (option (OPTRESOLVE)) {
1611 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1612 menu->current = menu->oldcurrent;
1613 menu->redraw = REDRAW_CURRENT;
1616 menu->redraw = REDRAW_MOTION_RESYNCH;
1619 menu->redraw = REDRAW_CURRENT;
1620 menu->redraw |= REDRAW_STATUS;
1624 case OP_TOGGLE_WRITE:
1627 if (mx_toggle_write (Context) == 0)
1628 menu->redraw |= REDRAW_STATUS;
1631 case OP_MAIN_NEXT_THREAD:
1632 case OP_MAIN_NEXT_SUBTHREAD:
1633 case OP_MAIN_PREV_THREAD:
1634 case OP_MAIN_PREV_SUBTHREAD:
1639 case OP_MAIN_NEXT_THREAD:
1640 menu->current = mutt_next_thread (CURHDR);
1643 case OP_MAIN_NEXT_SUBTHREAD:
1644 menu->current = mutt_next_subthread (CURHDR);
1647 case OP_MAIN_PREV_THREAD:
1648 menu->current = mutt_previous_thread (CURHDR);
1651 case OP_MAIN_PREV_SUBTHREAD:
1652 menu->current = mutt_previous_subthread (CURHDR);
1656 if (menu->current < 0) {
1657 menu->current = menu->oldcurrent;
1658 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1659 mutt_error (_("No more threads."));
1662 mutt_error (_("You are on the first thread."));
1664 else if (menu->menu == MENU_PAGER) {
1665 op = OP_DISPLAY_MESSAGE;
1669 menu->redraw = REDRAW_MOTION;
1672 case OP_MAIN_PARENT_MESSAGE:
1677 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1678 menu->current = menu->oldcurrent;
1680 else if (menu->menu == MENU_PAGER) {
1681 op = OP_DISPLAY_MESSAGE;
1685 menu->redraw = REDRAW_MOTION;
1688 case OP_MAIN_SET_FLAG:
1689 case OP_MAIN_CLEAR_FLAG:
1695 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0) {
1696 menu->redraw = REDRAW_STATUS;
1698 menu->redraw |= REDRAW_INDEX;
1699 else if (option (OPTRESOLVE)) {
1700 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1701 menu->current = menu->oldcurrent;
1702 menu->redraw |= REDRAW_CURRENT;
1705 menu->redraw |= REDRAW_MOTION_RESYNCH;
1708 menu->redraw |= REDRAW_CURRENT;
1712 case OP_MAIN_COLLAPSE_THREAD:
1716 if ((Sort & SORT_MASK) != SORT_THREADS) {
1717 mutt_error (_("Threading is not enabled."));
1722 if (CURHDR->collapsed) {
1723 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1724 mutt_set_virtual (Context);
1725 if (option (OPTUNCOLLAPSEJUMP))
1726 menu->current = mutt_thread_next_unread (Context, CURHDR);
1728 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1729 menu->current = mutt_collapse_thread (Context, CURHDR);
1730 mutt_set_virtual (Context);
1733 mutt_error (_("Thread contains unread messages."));
1738 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1742 case OP_MAIN_COLLAPSE_ALL:
1746 if ((Sort & SORT_MASK) != SORT_THREADS) {
1747 mutt_error (_("Threading is not enabled."));
1754 THREAD *thread, *top;
1757 if (CURHDR->collapsed)
1758 final = mutt_uncollapse_thread (Context, CURHDR);
1759 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1760 final = mutt_collapse_thread (Context, CURHDR);
1762 final = CURHDR->virtual;
1764 base = Context->hdrs[Context->v2r[final]];
1766 top = Context->tree;
1767 Context->collapsed = !Context->collapsed;
1768 while ((thread = top) != NULL) {
1769 while (!thread->message)
1770 thread = thread->child;
1771 h = thread->message;
1773 if (h->collapsed != Context->collapsed) {
1775 mutt_uncollapse_thread (Context, h);
1776 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1777 mutt_collapse_thread (Context, h);
1782 mutt_set_virtual (Context);
1783 for (j = 0; j < Context->vcount; j++) {
1784 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1790 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1794 /* --------------------------------------------------------------------
1795 * These functions are invoked directly from the internal-pager
1798 case OP_BOUNCE_MESSAGE:
1803 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1806 case OP_CREATE_ALIAS:
1808 mutt_create_alias (Context
1809 && Context->vcount ? CURHDR->env : NULL, NULL);
1810 MAYBE_REDRAW (menu->redraw);
1811 menu->redraw |= REDRAW_CURRENT;
1816 mutt_query_menu (NULL, 0);
1817 MAYBE_REDRAW (menu->redraw);
1820 case OP_PURGE_MESSAGE:
1827 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1830 mutt_tag_set_flag (M_DELETE, 1);
1831 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1832 if (option (OPTDELETEUNTAG))
1833 mutt_tag_set_flag (M_TAG, 0);
1834 menu->redraw = REDRAW_INDEX;
1837 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1838 mutt_set_flag (Context, CURHDR, M_PURGED,
1839 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1840 if (option (OPTDELETEUNTAG))
1841 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1842 if (option (OPTRESOLVE)) {
1843 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1844 menu->current = menu->oldcurrent;
1845 menu->redraw = REDRAW_CURRENT;
1847 else if (menu->menu == MENU_PAGER) {
1848 op = OP_DISPLAY_MESSAGE;
1852 menu->redraw |= REDRAW_MOTION_RESYNCH;
1855 menu->redraw = REDRAW_CURRENT;
1857 menu->redraw |= REDRAW_STATUS;
1860 case OP_DELETE_THREAD:
1861 case OP_DELETE_SUBTHREAD:
1867 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1869 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1870 op == OP_DELETE_THREAD ? 0 : 1);
1873 if (option (OPTDELETEUNTAG))
1874 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1875 op == OP_DELETE_THREAD ? 0 : 1);
1876 if (option (OPTRESOLVE))
1877 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1878 menu->current = menu->oldcurrent;
1879 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1885 if (Context && Context->magic == M_NNTP) {
1886 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1887 ((nntp_data_t *) Context->data)->group))
1888 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1893 case OP_DISPLAY_ADDRESS:
1897 mutt_display_address (CURHDR->env);
1900 case OP_ENTER_COMMAND:
1902 CurrentMenu = MENU_MAIN;
1903 mutt_enter_command ();
1904 mutt_check_rescore (Context);
1905 if (option (OPTFORCEREDRAWINDEX))
1906 menu->redraw = REDRAW_FULL;
1907 unset_option (OPTFORCEREDRAWINDEX);
1908 unset_option (OPTFORCEREDRAWPAGER);
1911 case OP_EDIT_MESSAGE:
1918 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1920 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1921 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1922 mutt_edit_message (Context, tag ? NULL : CURHDR);
1923 menu->redraw = REDRAW_FULL;
1927 case OP_FORWARD_MESSAGE:
1933 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1934 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1935 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
1936 menu->redraw = REDRAW_FULL;
1939 case OP_GROUP_REPLY:
1945 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1946 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1948 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
1949 tag ? NULL : CURHDR);
1950 menu->redraw = REDRAW_FULL;
1959 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1960 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1962 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
1963 tag ? NULL : CURHDR);
1964 menu->redraw = REDRAW_FULL;
1970 ci_send_message (0, NULL, NULL, Context, NULL);
1971 menu->redraw = REDRAW_FULL;
1974 case OP_EXTRACT_KEYS:
1977 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
1978 menu->redraw = REDRAW_FULL;
1982 case OP_CHECK_TRADITIONAL:
1985 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1986 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1988 if (menu->menu == MENU_PAGER) {
1989 op = OP_DISPLAY_MESSAGE;
1997 mutt_pipe_message (tag ? NULL : CURHDR);
1998 MAYBE_REDRAW (menu->redraw);
2004 mutt_print_message (tag ? NULL : CURHDR);
2007 case OP_MAIN_READ_THREAD:
2008 case OP_MAIN_READ_SUBTHREAD:
2013 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2015 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2016 op == OP_MAIN_READ_THREAD ? 0 : 1);
2019 if (option (OPTRESOLVE)) {
2020 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2021 mutt_next_thread (CURHDR) :
2022 mutt_next_subthread (CURHDR))) == -1)
2023 menu->current = menu->oldcurrent;
2025 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2029 case OP_RECALL_MESSAGE:
2032 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2033 menu->redraw = REDRAW_FULL;
2043 for (j = 0; j < Context->vcount; j++) {
2044 if (Context->hdrs[Context->v2r[j]]->tagged)
2045 mutt_resend_message (NULL, Context,
2046 Context->hdrs[Context->v2r[j]]);
2050 mutt_resend_message (NULL, Context, CURHDR);
2052 menu->redraw = REDRAW_FULL;
2058 case OP_FORWARD_TO_GROUP:
2061 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2062 Context && Context->msgcount == 0) {
2063 mutt_error (_("There are no messages."));
2066 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2067 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2068 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2069 _("Reply by mail as poster prefers?")) !=
2071 if (Context && Context->magic == M_NNTP
2072 && !((nntp_data_t *) Context->data)->allowed
2073 && query_quadoption (OPT_TOMODERATED,
2075 ("Posting to this group not allowed, may be moderated. Continue?"))
2079 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2082 if (op == OP_FOLLOWUP)
2083 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2084 tag ? NULL : CURHDR);
2086 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2087 tag ? NULL : CURHDR);
2089 menu->redraw = REDRAW_FULL;
2100 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2101 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2103 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2104 menu->redraw = REDRAW_FULL;
2107 case OP_SHELL_ESCAPE:
2109 mutt_shell_escape ();
2110 MAYBE_REDRAW (menu->redraw);
2114 case OP_TAG_SUBTHREAD:
2118 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2119 op == OP_TAG_THREAD ? 0 : 1);
2122 if (option (OPTRESOLVE)) {
2123 menu->current = mutt_next_thread (CURHDR);
2125 if (menu->current == -1)
2126 menu->current = menu->oldcurrent;
2128 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2138 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2141 mutt_tag_set_flag (M_DELETE, 0);
2142 mutt_tag_set_flag (M_PURGED, 0);
2143 menu->redraw = REDRAW_INDEX;
2146 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2147 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2148 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2150 menu->redraw = REDRAW_MOTION_RESYNCH;
2153 menu->redraw = REDRAW_CURRENT;
2155 menu->redraw |= REDRAW_STATUS;
2158 case OP_UNDELETE_THREAD:
2159 case OP_UNDELETE_SUBTHREAD:
2165 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2167 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2168 op == OP_UNDELETE_THREAD ? 0 : 1)
2169 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2170 op == OP_UNDELETE_THREAD ? 0 : 1);
2173 if (option (OPTRESOLVE)) {
2174 if (op == OP_UNDELETE_THREAD)
2175 menu->current = mutt_next_thread (CURHDR);
2177 menu->current = mutt_next_subthread (CURHDR);
2179 if (menu->current == -1)
2180 menu->current = menu->oldcurrent;
2182 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2191 if (option (OPTFORCEBUFFYCHECK))
2194 menu->redraw = REDRAW_FULL;
2197 case OP_VIEW_ATTACHMENTS:
2200 mutt_view_attachments (CURHDR);
2201 if (CURHDR->attach_del)
2202 Context->changed = 1;
2203 menu->redraw = REDRAW_FULL;
2213 case OP_SIDEBAR_SCROLL_UP:
2214 case OP_SIDEBAR_SCROLL_DOWN:
2215 case OP_SIDEBAR_NEXT:
2216 case OP_SIDEBAR_PREV:
2217 case OP_SIDEBAR_NEXT_NEW:
2218 case OP_SIDEBAR_PREV_NEW:
2219 sidebar_scroll (op);
2222 if (menu->menu == MENU_MAIN)
2223 km_error_key (MENU_MAIN);
2226 if (menu->menu == MENU_PAGER) {
2227 menu->menu = MENU_MAIN;
2228 menu->redraw = REDRAW_FULL;
2236 /* Close all open IMAP connections */
2239 /* Close all open NNTP connections */
2244 mutt_menuDestroy (&menu);
2248 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2255 for (color = ColorIndexList; color; color = color->next)
2256 if (mutt_pattern_exec
2257 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2258 curhdr->pair = color->pair;
2261 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];