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>
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 ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
102 flag |= M_FORMAT_TREE; /* display the thread tree */
103 if (h->display_subject)
104 flag |= M_FORMAT_FORCESUBJ;
107 if (menu->top + menu->pagelen > menu->max)
108 edgemsgno = Context->v2r[menu->max - 1];
110 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
113 edgemsgno = Context->v2r[menu->top];
115 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
119 /* if no ancestor is visible on current screen, provisionally force
121 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
123 flag |= M_FORMAT_FORCESUBJ;
126 else if (tmp->message->virtual >= 0)
129 if (flag & M_FORMAT_FORCESUBJ) {
130 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
134 /* ...but if a previous sibling is available, don't force it */
135 if (reverse ? tmp->message->msgno >
136 edgemsgno : tmp->message->msgno < edgemsgno)
138 else if (tmp->message->virtual >= 0) {
139 flag &= ~M_FORMAT_FORCESUBJ;
147 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
150 int index_color (int index_no)
152 HEADER *h = Context->hdrs[Context->v2r[index_no]];
157 mutt_set_header_color (Context, h);
161 static int ci_next_undeleted (int msgno)
165 for (i = msgno + 1; i < Context->vcount; i++)
166 if (!Context->hdrs[Context->v2r[i]]->deleted)
171 static int ci_previous_undeleted (int msgno)
175 for (i = msgno - 1; i >= 0; i--)
176 if (!Context->hdrs[Context->v2r[i]]->deleted)
181 /* Return the index of the first new message, or failing that, the first
184 static int ci_first_message (void)
188 if (Context && Context->msgcount) {
189 for (i = 0; i < Context->vcount; i++) {
190 if (!Context->hdrs[Context->v2r[i]]->read &&
191 !Context->hdrs[Context->v2r[i]]->deleted) {
192 if (!Context->hdrs[Context->v2r[i]]->old)
201 /* If Sort is reverse and not threaded, the latest message is first.
202 * If Sort is threaded, the latest message is first iff exactly one
203 * of Sort and SortAux are reverse.
205 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
206 ((Sort & SORT_MASK) == SORT_THREADS &&
207 ((Sort ^ SortAux) & SORT_REVERSE)))
210 return (Context->vcount ? Context->vcount - 1 : 0);
215 /* This should be in mx.c, but it only gets used here. */
216 static int mx_toggle_write (CONTEXT * ctx)
222 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
227 if (ctx->dontwrite) {
229 mutt_message (_("Changes to folder will be written on folder exit."));
233 mutt_message (_("Changes to folder will not be written."));
239 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
240 int oldcount, int index_hint)
242 /* store pointers to the newly added messages */
243 HEADER **save_new = NULL;
246 /* take note of the current message */
248 if (menu->current < Context->vcount)
249 menu->oldcurrent = index_hint;
251 oldcount = 0; /* invalid message number! */
254 /* We are in a limited view. Check if the new message(s) satisfy
255 * the limit criteria. If they do, set their virtual msgno so that
256 * they will be visible in the limited view */
257 if (Context->pattern) {
258 #define THIS_BODY Context->hdrs[j]->content
259 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
260 if (mutt_pattern_exec
261 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
263 Context->hdrs[j]->virtual = Context->vcount;
264 Context->v2r[Context->vcount] = j;
265 Context->hdrs[j]->limited = 1;
268 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
274 /* save the list of new messages */
275 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
276 save_new = p_new(HEADER*, Context->msgcount - oldcount);
277 for (j = oldcount; j < Context->msgcount; j++)
278 save_new[j - oldcount] = Context->hdrs[j];
281 /* if the mailbox was reopened, need to rethread from scratch */
282 mutt_sort_headers (Context, (check == M_REOPENED));
284 /* uncollapse threads with new mail */
285 if ((Sort & SORT_MASK) == SORT_THREADS) {
286 if (check == M_REOPENED) {
289 Context->collapsed = 0;
291 for (h = Context->tree; h; h = h->next) {
292 for (c = h; !c->message; c = c->child);
293 mutt_uncollapse_thread (Context, c->message);
295 mutt_set_virtual (Context);
298 for (j = 0; j < Context->msgcount - oldcount; j++) {
301 for (k = 0; k < Context->msgcount; k++) {
302 HEADER *h = Context->hdrs[k];
304 if (h == save_new[j] && (!Context->pattern || h->limited))
305 mutt_uncollapse_thread (Context, h);
309 mutt_set_virtual (Context);
315 /* restore the current message to the message it was pointing to */
316 for (j = 0; j < Context->vcount; j++) {
317 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
324 if (menu->current < 0)
325 menu->current = ci_first_message ();
328 static void resort_index (MUTTMENU * menu)
331 HEADER *current = CURHDR;
334 mutt_sort_headers (Context, 0);
335 /* Restore the current message */
337 for (i = 0; i < Context->vcount; i++) {
338 if (Context->hdrs[Context->v2r[i]] == current) {
344 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
345 menu->current = mutt_parent_message (Context, current);
347 if (menu->current < 0)
348 menu->current = ci_first_message ();
350 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
353 /* This function handles the message index window as well as commands returned
354 * from the pager (MENU_PAGER).
356 int mutt_index_menu (void)
358 char buf[LONG_STRING];
361 int done = 0; /* controls when to exit the "event" loop */
363 int tag = 0; /* has the tag-prefix command been pressed? */
368 const char *cp; /* temporary variable. */
369 int index_hint; /* used to restore cursor position */
370 int do_buffy_notify = 1;
371 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
372 int attach_msg = option (OPTATTACHMSG);
374 menu = mutt_new_menu ();
375 menu->menu = MENU_MAIN;
377 menu->pagelen = LINES - 3;
378 menu->make_entry = (void *) index_make_entry;
379 menu->color = index_color;
380 menu->current = ci_first_message ();
383 buffy_check (0); /* force the buffy check after we enter the folder */
384 /* record folder we open to place sidebar indicator properly */
385 if (Context && Context->path)
386 sidebar_set_current (Context->path);
390 tag = 0; /* clear the tag-prefix */
392 menu->max = Context ? Context->vcount : 0;
393 oldcount = Context ? Context->msgcount : 0;
395 /* check if we need to resort the index because just about
396 * any 'op' below could do mutt_enter_command(), either here or
397 * from any new menu launched, and change $sort/$sort_aux
399 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
402 if (option (OPTREDRAWTREE) && Context && Context->msgcount
403 && (Sort & SORT_MASK) == SORT_THREADS) {
404 mutt_draw_tree (Context);
405 menu->redraw |= REDRAW_STATUS;
406 unset_option (OPTREDRAWTREE);
409 if (Context && !attach_msg) {
412 /* check for new mail in the mailbox. If nonzero, then something has
413 * changed about the file (either we got new mail or the file was
414 * modified underneath us.)
417 imap_allow_reopen (Context);
419 index_hint = (Context->vcount && menu->current >= 0
420 && menu->current < Context->vcount) ? CURHDR->index : 0;
422 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
423 if (!Context->path) {
424 /* fatal error occurred */
426 menu->redraw = REDRAW_FULL;
428 set_option (OPTSEARCHINVALID);
430 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
431 update_index (menu, Context, check, oldcount, index_hint);
433 /* notify the user of new mail */
434 if (check == M_REOPENED)
436 ("Mailbox was externally modified. Flags may be wrong."));
437 else if (check == M_NEW_MAIL) {
438 /* on new mail: redraw sidebar */
440 mutt_message (_("New mail in this mailbox."));
442 if (mod_core.beep_new)
445 else if (check == M_FLAGS)
446 mutt_message (_("Mailbox was externally modified."));
448 /* avoid the message being overwritten by buffy */
451 menu->redraw = REDRAW_FULL;
452 menu->max = Context->vcount;
454 set_option (OPTSEARCHINVALID);
459 imap_disallow_reopen (Context);
462 /* check for new mail in the incoming folders */
464 if ((newcount = buffy_check (0)) != oldcount) {
465 menu->redraw |= REDRAW_STATUS;
466 menu->redraw |= REDRAW_SIDEBAR;
468 if (do_buffy_notify) {
469 if (buffy_notify () && mod_core.beep_new)
478 if (menu->redraw & REDRAW_SIDEBAR)
480 if (menu->redraw & REDRAW_FULL) {
481 menu_redraw_full (menu);
486 if (menu->menu == MENU_MAIN) {
487 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
488 menu_check_recenter (menu);
490 if (menu->redraw & REDRAW_INDEX) {
491 menu_redraw_index (menu);
492 menu->redraw |= REDRAW_STATUS;
494 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
495 menu_redraw_motion (menu);
496 else if (menu->redraw & REDRAW_CURRENT)
497 menu_redraw_current (menu);
500 if (menu->redraw & REDRAW_STATUS) {
501 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
502 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES - 2);
503 sidebar_draw_frames();
504 SETCOLOR (MT_COLOR_STATUS);
505 BKGDSET (MT_COLOR_STATUS);
506 wmove(stdscr, option (OPTSTATUSONTOP) ? 0 : LINES - 2,SW);
507 mutt_paddstr (COLS-SW, buf);
508 SETCOLOR (MT_COLOR_NORMAL);
509 BKGDSET (MT_COLOR_NORMAL);
510 sidebar_set_buffystats (Context);
511 menu->redraw &= ~REDRAW_STATUS;
512 if (option (OPTXTERMSETTITLES)) {
513 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermTitle));
514 printf("\033]2;%s\007", buf);
515 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermIcon));
516 printf("\033]1;%s\007", buf);
522 if (menu->current < menu->max)
523 menu->oldcurrent = menu->current;
525 menu->oldcurrent = -1;
527 if (option (OPTBRAILLEFRIENDLY))
528 wmove (stdscr, menu->current - menu->top + menu->offset, 0);
530 wmove (stdscr, menu->current - menu->top + menu->offset, COLS - 1);
535 mutt_resize_screen ();
536 menu->redraw = REDRAW_FULL;
537 menu->menu = MENU_MAIN;
539 menu->top = 0; /* so we scroll the right amount */
541 * force a real complete redraw. wclrtobot(stdscr) doesn't seem to be able
542 * to handle every case without this.
544 clearok (stdscr, TRUE);
548 op = km_dokey (MENU_MAIN);
550 continue; /* either user abort or timeout */
554 /* special handling for the tag-prefix function */
555 if (op == OP_TAG_PREFIX) {
557 mutt_error (_("No mailbox is open."));
562 if (!Context->tagged) {
563 mutt_error (_("No tagged messages."));
569 /* give visual indication that the next command is a tag- command */
570 mvwaddstr (stdscr, LINES - 1, 0, "tag-");
573 /* get the real command */
574 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
575 /* abort tag sequence */
576 CLEARLINE (LINES - 1);
580 else if (option (OPTAUTOTAG) && Context && Context->tagged)
583 if (op == OP_TAG_PREFIX_COND) {
585 mutt_error (_("No mailbox is open."));
590 if (!Context->tagged) {
593 while (UngetCount > 0) {
595 if (tmp.op == OP_END_COND)
598 mutt_message (_("Nothing to do."));
604 /* give visual indication that the next command is a tag- command */
605 mvwaddstr (stdscr, LINES - 1, 0, "tag-");
608 /* get the real command */
609 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
610 /* abort tag sequence */
611 CLEARLINE (LINES - 1);
619 if (menu->current < menu->max)
620 menu->oldcurrent = menu->current;
622 menu->oldcurrent = -1;
624 mutt_curs_set (1); /* fallback from the pager */
628 unset_option (OPTNEWS); /* for any case */
633 /* ----------------------------------------------------------------------
638 menu_bottom_page (menu);
641 menu_first_entry (menu);
644 menu_middle_page (menu);
650 menu_half_down (menu);
653 menu_next_line (menu);
656 menu_prev_line (menu);
659 menu_next_page (menu);
662 menu_prev_page (menu);
665 menu_last_entry (menu);
668 menu_top_page (menu);
671 menu_current_top (menu);
673 case OP_CURRENT_MIDDLE:
674 menu_current_middle (menu);
676 case OP_CURRENT_BOTTOM:
677 menu_current_bottom (menu);
684 if (Context->magic == M_NNTP) {
687 if (op == OP_GET_MESSAGE) {
689 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
694 string_list_t *ref = CURHDR->env->references;
697 mutt_error (_("Article has no parent reference!"));
701 m_strcpy(buf, sizeof(buf), ref->data);
703 if (!Context->id_hash)
704 Context->id_hash = mutt_make_id_hash (Context);
705 if ((h = hash_find (Context->id_hash, buf))) {
706 if (h->virtual != -1) {
707 menu->current = h->virtual;
708 menu->redraw = REDRAW_MOTION_RESYNCH;
710 else if (h->collapsed) {
711 mutt_uncollapse_thread (Context, h);
712 mutt_set_virtual (Context);
713 menu->current = h->virtual;
714 menu->redraw = REDRAW_MOTION_RESYNCH;
717 mutt_error (_("Message not visible in limited view."));
720 if (nntp_check_msgid (Context, buf) == 0) {
721 h = Context->hdrs[Context->msgcount - 1];
722 mutt_sort_headers (Context, 0);
723 menu->current = h->virtual;
724 menu->redraw = REDRAW_FULL;
727 mutt_error (_("Article %s not found on server"), buf);
732 case OP_GET_CHILDREN:
733 case OP_RECONSTRUCT_THREAD:
735 if (Context->magic == M_NNTP) {
737 int old = CURHDR->index;
739 if (!CURHDR->env->message_id) {
740 mutt_error (_("No Message-ID. Unable to perform operation"));
745 if (!Context->id_hash)
746 Context->id_hash = mutt_make_id_hash (Context);
747 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
749 if (op == OP_RECONSTRUCT_THREAD) {
750 string_list_t *ref = CURHDR->env->references;
753 nntp_check_msgid (Context, ref->data);
754 /* the last msgid in References is the root message */
756 m_strcpy(buf, sizeof(buf), ref->data);
760 mutt_message (_("Check for children of message..."));
762 if (nntp_check_children (Context, buf) == 0) {
763 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
764 h = hash_find (Context->id_hash, buf);
765 /* if the root message was retrieved, move to it */
767 menu->current = h->virtual;
768 else /* try to restore old position */
769 for (i = 0; i < Context->msgcount; i++)
770 if (Context->hdrs[i]->index == old) {
771 menu->current = Context->hdrs[i]->virtual;
772 /* As an added courtesy, recenter the menu
773 * with the current entry at the middle of the screen */
774 menu_check_recenter (menu);
775 menu_current_middle (menu);
778 menu->redraw = REDRAW_FULL;
788 if (isdigit (LastKey))
789 mutt_ungetch (LastKey, 0);
791 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
795 if (!isdigit ((unsigned char) buf[0])) {
796 mutt_error (_("Argument must be a message number."));
802 if (i > 0 && i <= Context->msgcount) {
803 for (j = i - 1; j < Context->msgcount; j++) {
804 if (Context->hdrs[j]->virtual != -1)
807 if (j >= Context->msgcount) {
808 for (j = i - 2; j >= 0; j--) {
809 if (Context->hdrs[j]->virtual != -1)
815 menu->current = Context->hdrs[j]->virtual;
816 if (menu->menu == MENU_PAGER) {
817 op = OP_DISPLAY_MESSAGE;
821 menu->redraw = REDRAW_MOTION;
824 mutt_error (_("That message is not visible."));
827 mutt_error (_("Invalid message number."));
831 /* --------------------------------------------------------------------
832 * `index' specific commands
835 case OP_MAIN_DELETE_PATTERN:
841 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
844 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
845 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
848 case OP_MAIN_FETCH_MAIL:
852 menu->redraw = REDRAW_FULL;
857 mutt_help (MENU_MAIN);
858 menu->redraw = REDRAW_FULL;
861 case OP_MAIN_SHOW_LIMIT:
863 if (!Context->pattern)
864 mutt_message (_("No limit pattern is in effect."));
869 /* i18n: ask for a limit to apply */
870 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
871 mutt_message ("%s", buffer);
879 menu->oldcurrent = (Context->vcount && menu->current >= 0
881 Context->vcount) ? CURHDR->index : -1;
882 if (op == OP_TOGGLE_READ) {
883 char buffer[LONG_STRING];
885 if (m_strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
886 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
887 Context->pattern ? Context->pattern : ".*");
888 set_option (OPTHIDEREAD);
891 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
892 if (m_strncmp (buf, ".*", 2) == 0)
893 snprintf (buf, sizeof (buf), "~A");
894 unset_option (OPTHIDEREAD);
896 p_delete(&Context->pattern);
897 Context->pattern = m_strdup(buf);
899 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
900 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
902 if (menu->oldcurrent >= 0) {
903 /* try to find what used to be the current message */
905 for (i = 0; i < Context->vcount; i++)
906 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
910 if (menu->current < 0)
915 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
916 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
917 mutt_draw_tree (Context);
918 menu->redraw = REDRAW_FULL;
920 if (Context->pattern)
921 mutt_message _("To view all messages, limit to \"all\".");
932 if (query_quadoption2(mod_core.quit, _("Quit Madmutt?")) == M_YES) {
935 oldcount = Context ? Context->msgcount : 0;
938 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
941 if (check == M_NEW_MAIL || check == M_REOPENED)
942 update_index (menu, Context, check, oldcount, index_hint);
944 menu->redraw = REDRAW_FULL; /* new mail arrived? */
945 set_option (OPTSEARCHINVALID);
952 clearok (stdscr, TRUE);
953 menu->redraw = REDRAW_FULL;
957 case OP_SEARCH_REVERSE:
959 case OP_SEARCH_OPPOSITE:
963 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
964 menu->current = menu->oldcurrent;
966 menu->redraw = REDRAW_MOTION;
970 case OP_SORT_REVERSE:
972 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
973 if (Context && Context->msgcount) {
975 set_option (OPTSEARCHINVALID);
984 if (tag && !option (OPTAUTOTAG)) {
985 for (j = 0; j < Context->vcount; j++)
986 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
987 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
990 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
991 Context->last_tag = CURHDR->tagged ? CURHDR :
992 ((Context->last_tag == CURHDR && !CURHDR->tagged)
993 ? NULL : Context->last_tag);
994 menu->redraw = REDRAW_STATUS;
995 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
997 menu->redraw |= REDRAW_MOTION_RESYNCH;
1000 menu->redraw |= REDRAW_CURRENT;
1004 case OP_MAIN_TAG_PATTERN:
1008 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1009 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1012 case OP_MAIN_UNDELETE_PATTERN:
1018 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1020 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1022 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1025 case OP_MAIN_UNTAG_PATTERN:
1029 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1030 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1033 /* --------------------------------------------------------------------
1034 * The following operations can be performed inside of the pager.
1037 case OP_MAIN_IMAP_FETCH:
1038 if (Context->magic == M_IMAP)
1039 imap_check_mailbox (Context, &index_hint, 1);
1042 case OP_MAIN_SYNC_FOLDER:
1044 if (Context && !Context->msgcount)
1051 int oldvcount = Context->vcount;
1052 oldcount = Context->msgcount;
1056 /* calculate the number of messages _above_ the cursor,
1057 * so we can keep the cursor on the current message
1059 for (j = 0; j <= menu->current; j++) {
1060 if (Context->hdrs[Context->v2r[j]]->deleted)
1064 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1065 if (Context->vcount != oldvcount)
1066 menu->current -= dcount;
1067 set_option (OPTSEARCHINVALID);
1069 else if (check == M_NEW_MAIL || check == M_REOPENED)
1070 update_index (menu, Context, check, oldcount, index_hint);
1073 * do a sanity check even if mx_sync_mailbox failed.
1076 if (menu->current < 0 || menu->current >= Context->vcount)
1077 menu->current = ci_first_message ();
1080 /* check for a fatal error, or all messages deleted */
1084 /* if we were in the pager, redisplay the message */
1085 if (menu->menu == MENU_PAGER) {
1086 op = OP_DISPLAY_MESSAGE;
1090 menu->redraw = REDRAW_FULL;
1093 case OP_SIDEBAR_OPEN:
1094 case OP_MAIN_CHANGE_FOLDER:
1095 case OP_MAIN_CHANGE_FOLDER_READONLY:
1097 case OP_MAIN_CHANGE_GROUP:
1098 case OP_MAIN_CHANGE_GROUP_READONLY:
1100 if (attach_msg || option (OPTREADONLY) ||
1102 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1104 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1110 cp = _("Open mailbox in read-only mode");
1112 cp = _("Open mailbox");
1116 unset_option (OPTNEWS);
1117 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1118 set_option (OPTNEWS);
1119 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1122 cp = _("Open newsgroup in read-only mode");
1124 cp = _("Open newsgroup");
1125 nntp_buffy (buf, sizeof (buf));
1130 if (Context && Context->path)
1131 m_strcpy(buf, sizeof(buf), Context->path);
1132 if (op != OP_SIDEBAR_OPEN)
1133 buffy_next (buf, sizeof (buf));
1136 if (op == OP_SIDEBAR_OPEN) {
1137 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1139 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1140 if (menu->menu == MENU_PAGER) {
1141 op = OP_DISPLAY_MESSAGE;
1147 CLEARLINE (LINES - 1);
1152 if (option (OPTNEWS)) {
1153 unset_option (OPTNEWS);
1154 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1158 mutt_expand_path (buf, sizeof (buf));
1159 if (mx_get_magic (buf) <= 0) {
1160 mutt_error (_("%s is not a mailbox."), buf);
1163 m_strreplace(&CurrentFolder, buf);
1168 if (Context->cinfo && Context->realpath)
1169 m_strreplace(&LastFolder, Context->realpath);
1171 m_strreplace(&LastFolder, Context->path);
1172 oldcount = Context ? Context->msgcount : 0;
1174 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1175 if (check == M_NEW_MAIL || check == M_REOPENED)
1176 update_index (menu, Context, check, oldcount, index_hint);
1178 set_option (OPTSEARCHINVALID);
1179 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1187 /* Set CurrentMenu to MENU_MAIN before executing any folder
1188 * hooks so that all the index menu functions are available to
1192 CurrentMenu = MENU_MAIN;
1193 mutt_folder_hook (buf);
1195 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1196 menu->current = ci_first_message ();
1200 sidebar_set_current (buf);
1202 mutt_clear_error ();
1203 buffy_check (0); /* force the buffy check after we have changed
1205 menu->redraw = REDRAW_FULL;
1206 set_option (OPTSEARCHINVALID);
1209 case OP_DISPLAY_MESSAGE:
1210 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1215 * toggle the weeding of headers so that a user can press the key
1216 * again while reading the message.
1218 if (op == OP_DISPLAY_HEADERS)
1219 toggle_option (OPTWEED);
1221 unset_option (OPTNEEDRESORT);
1223 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1224 mutt_uncollapse_thread (Context, CURHDR);
1225 mutt_set_virtual (Context);
1226 if (option (OPTUNCOLLAPSEJUMP))
1227 menu->current = mutt_thread_next_unread (Context, CURHDR);
1230 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1231 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1233 if ((op = mutt_display_message (CURHDR)) == -1) {
1234 unset_option (OPTNEEDRESORT);
1238 menu->menu = MENU_PAGER;
1239 menu->oldcurrent = menu->current;
1245 if (menu->menu == MENU_MAIN && attach_msg) {
1250 if ((menu->menu == MENU_MAIN)
1251 && (query_quadoption2(mod_core.quit,
1252 _("Exit Madmutt without saving?")) == M_YES))
1255 mx_fastclose_mailbox (Context);
1267 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1268 /* if we were in the pager, redisplay the message */
1269 if (menu->menu == MENU_PAGER) {
1270 op = OP_DISPLAY_MESSAGE;
1274 menu->redraw = REDRAW_CURRENT;
1277 case OP_MAIN_BREAK_THREAD:
1283 if ((Sort & SORT_MASK) != SORT_THREADS)
1284 mutt_error (_("Threading is not enabled."));
1288 HEADER *oldcur = CURHDR;
1290 mutt_break_thread (CURHDR);
1291 mutt_sort_headers (Context, 1);
1292 menu->current = oldcur->virtual;
1295 Context->changed = 1;
1296 mutt_message _("Thread broken");
1298 if (menu->menu == MENU_PAGER) {
1299 op = OP_DISPLAY_MESSAGE;
1303 menu->redraw |= REDRAW_INDEX;
1307 case OP_MAIN_LINK_THREADS:
1313 if ((Sort & SORT_MASK) != SORT_THREADS)
1314 mutt_error (_("Threading is not enabled."));
1316 else if (!CURHDR->env->message_id)
1317 mutt_error (_("No Message-ID: header available to link thread"));
1319 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1320 mutt_error (_("First, please tag a message to be linked here"));
1323 HEADER *oldcur = CURHDR;
1325 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1327 mutt_sort_headers (Context, 1);
1328 menu->current = oldcur->virtual;
1330 Context->changed = 1;
1331 mutt_message _("Threads linked");
1334 mutt_error (_("No thread linked"));
1337 if (menu->menu == MENU_PAGER) {
1338 op = OP_DISPLAY_MESSAGE;
1342 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1345 case OP_MAIN_NEXT_UNDELETED:
1349 if (menu->current >= Context->vcount - 1) {
1350 if (menu->menu == MENU_MAIN)
1351 mutt_error (_("You are on the last message."));
1355 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1356 menu->current = menu->oldcurrent;
1357 if (menu->menu == MENU_MAIN)
1358 mutt_error (_("No undeleted messages."));
1360 else if (menu->menu == MENU_PAGER) {
1361 op = OP_DISPLAY_MESSAGE;
1365 menu->redraw = REDRAW_MOTION;
1372 if (menu->current >= Context->vcount - 1) {
1373 if (menu->menu == MENU_MAIN)
1374 mutt_error (_("You are on the last message."));
1379 if (menu->menu == MENU_PAGER) {
1380 op = OP_DISPLAY_MESSAGE;
1384 menu->redraw = REDRAW_MOTION;
1387 case OP_MAIN_PREV_UNDELETED:
1391 if (menu->current < 1) {
1392 mutt_error (_("You are on the first message."));
1396 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1397 menu->current = menu->oldcurrent;
1398 if (menu->menu == MENU_MAIN)
1399 mutt_error (_("No undeleted messages."));
1401 else if (menu->menu == MENU_PAGER) {
1402 op = OP_DISPLAY_MESSAGE;
1406 menu->redraw = REDRAW_MOTION;
1413 if (menu->current < 1) {
1414 if (menu->menu == MENU_MAIN)
1415 mutt_error (_("You are on the first message."));
1420 if (menu->menu == MENU_PAGER) {
1421 op = OP_DISPLAY_MESSAGE;
1425 menu->redraw = REDRAW_MOTION;
1428 case OP_DECRYPT_COPY:
1429 case OP_DECRYPT_SAVE:
1430 case OP_COPY_MESSAGE:
1432 case OP_DECODE_COPY:
1433 case OP_DECODE_SAVE:
1436 if (mutt_save_message (tag ? NULL : CURHDR,
1437 (op == OP_DECRYPT_SAVE) ||
1438 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1439 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1440 (op == OP_DECRYPT_SAVE)
1441 || (op == OP_DECRYPT_COPY)
1442 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1449 menu->redraw |= REDRAW_INDEX;
1450 else if (option (OPTRESOLVE)) {
1451 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1452 menu->current = menu->oldcurrent;
1453 menu->redraw |= REDRAW_CURRENT;
1456 menu->redraw |= REDRAW_MOTION_RESYNCH;
1459 menu->redraw |= REDRAW_CURRENT;
1463 case OP_MAIN_NEXT_NEW:
1464 case OP_MAIN_NEXT_UNREAD:
1465 case OP_MAIN_PREV_NEW:
1466 case OP_MAIN_PREV_UNREAD:
1467 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1468 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1471 int first_unread = -1;
1479 for (j = 0; j != Context->vcount; j++) {
1480 #define CURHDRi Context->hdrs[Context->v2r[i]]
1481 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1482 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1484 if (i > Context->vcount - 1) {
1485 mutt_message _("Search wrapped to top.");
1493 mutt_message _("Search wrapped to bottom.");
1495 i = Context->vcount - 1;
1499 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1500 if (UNREAD (CURHDRi) && first_unread == -1)
1502 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1505 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1506 if (first_unread == -1)
1508 if ((!CURHDRi->old) && first_new == -1)
1512 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1515 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1516 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1517 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1522 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1523 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1524 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1526 menu->current = first_new;
1527 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1528 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1529 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1530 && first_unread != -1)
1531 menu->current = first_unread;
1533 if (menu->current == -1) {
1534 menu->current = menu->oldcurrent;
1535 mutt_error ("%s%s.",
1536 (op == OP_MAIN_NEXT_NEW
1538 OP_MAIN_PREV_NEW) ? _("No new messages") :
1539 _("No unread messages"),
1540 Context->pattern ? _(" in this limited view") : "");
1542 else if (menu->menu == MENU_PAGER) {
1543 op = OP_DISPLAY_MESSAGE;
1547 menu->redraw = REDRAW_MOTION;
1550 case OP_FLAG_MESSAGE:
1556 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1559 for (j = 0; j < Context->vcount; j++) {
1560 if (Context->hdrs[Context->v2r[j]]->tagged)
1561 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1562 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1565 menu->redraw |= REDRAW_INDEX;
1568 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1569 if (option (OPTRESOLVE)) {
1570 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1571 menu->current = menu->oldcurrent;
1572 menu->redraw = REDRAW_CURRENT;
1575 menu->redraw = REDRAW_MOTION_RESYNCH;
1578 menu->redraw = REDRAW_CURRENT;
1580 menu->redraw |= REDRAW_STATUS;
1589 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1592 for (j = 0; j < Context->vcount; j++) {
1593 if (Context->hdrs[Context->v2r[j]]->tagged) {
1594 if (Context->hdrs[Context->v2r[j]]->read ||
1595 Context->hdrs[Context->v2r[j]]->old)
1596 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1599 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1603 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1606 if (CURHDR->read || CURHDR->old)
1607 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1609 mutt_set_flag (Context, CURHDR, M_READ, 1);
1611 if (option (OPTRESOLVE)) {
1612 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1613 menu->current = menu->oldcurrent;
1614 menu->redraw = REDRAW_CURRENT;
1617 menu->redraw = REDRAW_MOTION_RESYNCH;
1620 menu->redraw = REDRAW_CURRENT;
1621 menu->redraw |= REDRAW_STATUS;
1625 case OP_TOGGLE_WRITE:
1628 if (mx_toggle_write (Context) == 0)
1629 menu->redraw |= REDRAW_STATUS;
1632 case OP_MAIN_NEXT_THREAD:
1633 case OP_MAIN_NEXT_SUBTHREAD:
1634 case OP_MAIN_PREV_THREAD:
1635 case OP_MAIN_PREV_SUBTHREAD:
1640 case OP_MAIN_NEXT_THREAD:
1641 menu->current = mutt_next_thread (CURHDR);
1644 case OP_MAIN_NEXT_SUBTHREAD:
1645 menu->current = mutt_next_subthread (CURHDR);
1648 case OP_MAIN_PREV_THREAD:
1649 menu->current = mutt_previous_thread (CURHDR);
1652 case OP_MAIN_PREV_SUBTHREAD:
1653 menu->current = mutt_previous_subthread (CURHDR);
1657 if (menu->current < 0) {
1658 menu->current = menu->oldcurrent;
1659 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1660 mutt_error (_("No more threads."));
1663 mutt_error (_("You are on the first thread."));
1665 else if (menu->menu == MENU_PAGER) {
1666 op = OP_DISPLAY_MESSAGE;
1670 menu->redraw = REDRAW_MOTION;
1673 case OP_MAIN_PARENT_MESSAGE:
1678 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1679 menu->current = menu->oldcurrent;
1681 else if (menu->menu == MENU_PAGER) {
1682 op = OP_DISPLAY_MESSAGE;
1686 menu->redraw = REDRAW_MOTION;
1689 case OP_MAIN_SET_FLAG:
1690 case OP_MAIN_CLEAR_FLAG:
1696 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0) {
1697 menu->redraw = REDRAW_STATUS;
1699 menu->redraw |= REDRAW_INDEX;
1700 else if (option (OPTRESOLVE)) {
1701 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1702 menu->current = menu->oldcurrent;
1703 menu->redraw |= REDRAW_CURRENT;
1706 menu->redraw |= REDRAW_MOTION_RESYNCH;
1709 menu->redraw |= REDRAW_CURRENT;
1713 case OP_MAIN_COLLAPSE_THREAD:
1717 if ((Sort & SORT_MASK) != SORT_THREADS) {
1718 mutt_error (_("Threading is not enabled."));
1723 if (CURHDR->collapsed) {
1724 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1725 mutt_set_virtual (Context);
1726 if (option (OPTUNCOLLAPSEJUMP))
1727 menu->current = mutt_thread_next_unread (Context, CURHDR);
1729 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1730 menu->current = mutt_collapse_thread (Context, CURHDR);
1731 mutt_set_virtual (Context);
1734 mutt_error (_("Thread contains unread messages."));
1739 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1743 case OP_MAIN_COLLAPSE_ALL:
1747 if ((Sort & SORT_MASK) != SORT_THREADS) {
1748 mutt_error (_("Threading is not enabled."));
1755 THREAD *thread, *top;
1758 if (CURHDR->collapsed)
1759 final = mutt_uncollapse_thread (Context, CURHDR);
1760 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1761 final = mutt_collapse_thread (Context, CURHDR);
1763 final = CURHDR->virtual;
1765 base = Context->hdrs[Context->v2r[final]];
1767 top = Context->tree;
1768 Context->collapsed = !Context->collapsed;
1769 while ((thread = top) != NULL) {
1770 while (!thread->message)
1771 thread = thread->child;
1772 h = thread->message;
1774 if (h->collapsed != Context->collapsed) {
1776 mutt_uncollapse_thread (Context, h);
1777 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1778 mutt_collapse_thread (Context, h);
1783 mutt_set_virtual (Context);
1784 for (j = 0; j < Context->vcount; j++) {
1785 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1791 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1795 /* --------------------------------------------------------------------
1796 * These functions are invoked directly from the internal-pager
1799 case OP_BOUNCE_MESSAGE:
1804 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1807 case OP_CREATE_ALIAS:
1809 mutt_create_alias (Context
1810 && Context->vcount ? CURHDR->env : NULL, NULL);
1811 MAYBE_REDRAW (menu->redraw);
1812 menu->redraw |= REDRAW_CURRENT;
1817 mutt_query_menu (NULL, 0);
1818 MAYBE_REDRAW (menu->redraw);
1821 case OP_PURGE_MESSAGE:
1828 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1831 mutt_tag_set_flag (M_DELETE, 1);
1832 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1833 if (option (OPTDELETEUNTAG))
1834 mutt_tag_set_flag (M_TAG, 0);
1835 menu->redraw = REDRAW_INDEX;
1838 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1839 mutt_set_flag (Context, CURHDR, M_PURGED,
1840 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1841 if (option (OPTDELETEUNTAG))
1842 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1843 if (option (OPTRESOLVE)) {
1844 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1845 menu->current = menu->oldcurrent;
1846 menu->redraw = REDRAW_CURRENT;
1848 else if (menu->menu == MENU_PAGER) {
1849 op = OP_DISPLAY_MESSAGE;
1853 menu->redraw |= REDRAW_MOTION_RESYNCH;
1856 menu->redraw = REDRAW_CURRENT;
1858 menu->redraw |= REDRAW_STATUS;
1861 case OP_DELETE_THREAD:
1862 case OP_DELETE_SUBTHREAD:
1868 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1870 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1871 op == OP_DELETE_THREAD ? 0 : 1);
1874 if (option (OPTDELETEUNTAG))
1875 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1876 op == OP_DELETE_THREAD ? 0 : 1);
1877 if (option (OPTRESOLVE))
1878 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1879 menu->current = menu->oldcurrent;
1880 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1886 if (Context && Context->magic == M_NNTP) {
1887 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1888 ((nntp_data_t *) Context->data)->group))
1889 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1894 case OP_DISPLAY_ADDRESS:
1898 mutt_display_address (CURHDR->env);
1901 case OP_ENTER_COMMAND:
1903 CurrentMenu = MENU_MAIN;
1904 mutt_enter_command ();
1905 mutt_check_rescore (Context);
1906 if (option (OPTFORCEREDRAWINDEX))
1907 menu->redraw = REDRAW_FULL;
1908 unset_option (OPTFORCEREDRAWINDEX);
1909 unset_option (OPTFORCEREDRAWPAGER);
1912 case OP_EDIT_MESSAGE:
1919 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1921 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1922 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1923 mutt_edit_message (Context, tag ? NULL : CURHDR);
1924 menu->redraw = REDRAW_FULL;
1928 case OP_FORWARD_MESSAGE:
1934 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1935 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1936 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
1937 menu->redraw = REDRAW_FULL;
1940 case OP_GROUP_REPLY:
1946 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1947 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1949 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
1950 tag ? NULL : CURHDR);
1951 menu->redraw = REDRAW_FULL;
1960 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1961 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1963 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
1964 tag ? NULL : CURHDR);
1965 menu->redraw = REDRAW_FULL;
1971 ci_send_message (0, NULL, NULL, Context, NULL);
1972 menu->redraw = REDRAW_FULL;
1975 case OP_EXTRACT_KEYS:
1978 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
1979 menu->redraw = REDRAW_FULL;
1983 case OP_CHECK_TRADITIONAL:
1986 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1987 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1989 if (menu->menu == MENU_PAGER) {
1990 op = OP_DISPLAY_MESSAGE;
1998 mutt_pipe_message (tag ? NULL : CURHDR);
1999 MAYBE_REDRAW (menu->redraw);
2005 mutt_print_message (tag ? NULL : CURHDR);
2008 case OP_MAIN_READ_THREAD:
2009 case OP_MAIN_READ_SUBTHREAD:
2014 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2016 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2017 op == OP_MAIN_READ_THREAD ? 0 : 1);
2020 if (option (OPTRESOLVE)) {
2021 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2022 mutt_next_thread (CURHDR) :
2023 mutt_next_subthread (CURHDR))) == -1)
2024 menu->current = menu->oldcurrent;
2026 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2030 case OP_RECALL_MESSAGE:
2033 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2034 menu->redraw = REDRAW_FULL;
2044 for (j = 0; j < Context->vcount; j++) {
2045 if (Context->hdrs[Context->v2r[j]]->tagged)
2046 mutt_resend_message (NULL, Context,
2047 Context->hdrs[Context->v2r[j]]);
2051 mutt_resend_message (NULL, Context, CURHDR);
2053 menu->redraw = REDRAW_FULL;
2059 case OP_FORWARD_TO_GROUP:
2062 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2063 Context && Context->msgcount == 0) {
2064 mutt_error (_("There are no messages."));
2067 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2068 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2069 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2070 _("Reply by mail as poster prefers?")) !=
2072 if (Context && Context->magic == M_NNTP
2073 && !((nntp_data_t *) Context->data)->allowed
2074 && query_quadoption (OPT_TOMODERATED,
2076 ("Posting to this group not allowed, may be moderated. Continue?"))
2080 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2083 if (op == OP_FOLLOWUP)
2084 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2085 tag ? NULL : CURHDR);
2087 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2088 tag ? NULL : CURHDR);
2090 menu->redraw = REDRAW_FULL;
2101 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2102 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2104 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2105 menu->redraw = REDRAW_FULL;
2108 case OP_SHELL_ESCAPE:
2110 mutt_shell_escape ();
2111 MAYBE_REDRAW (menu->redraw);
2115 case OP_TAG_SUBTHREAD:
2119 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2120 op == OP_TAG_THREAD ? 0 : 1);
2123 if (option (OPTRESOLVE)) {
2124 menu->current = mutt_next_thread (CURHDR);
2126 if (menu->current == -1)
2127 menu->current = menu->oldcurrent;
2129 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2139 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2142 mutt_tag_set_flag (M_DELETE, 0);
2143 mutt_tag_set_flag (M_PURGED, 0);
2144 menu->redraw = REDRAW_INDEX;
2147 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2148 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2149 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2151 menu->redraw = REDRAW_MOTION_RESYNCH;
2154 menu->redraw = REDRAW_CURRENT;
2156 menu->redraw |= REDRAW_STATUS;
2159 case OP_UNDELETE_THREAD:
2160 case OP_UNDELETE_SUBTHREAD:
2166 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2168 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2169 op == OP_UNDELETE_THREAD ? 0 : 1)
2170 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2171 op == OP_UNDELETE_THREAD ? 0 : 1);
2174 if (option (OPTRESOLVE)) {
2175 if (op == OP_UNDELETE_THREAD)
2176 menu->current = mutt_next_thread (CURHDR);
2178 menu->current = mutt_next_subthread (CURHDR);
2180 if (menu->current == -1)
2181 menu->current = menu->oldcurrent;
2183 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2192 if (option (OPTFORCEBUFFYCHECK))
2195 menu->redraw = REDRAW_FULL;
2198 case OP_VIEW_ATTACHMENTS:
2201 mutt_view_attachments (CURHDR);
2202 if (CURHDR->attach_del)
2203 Context->changed = 1;
2204 menu->redraw = REDRAW_FULL;
2214 case OP_SIDEBAR_SCROLL_UP:
2215 case OP_SIDEBAR_SCROLL_DOWN:
2216 case OP_SIDEBAR_NEXT:
2217 case OP_SIDEBAR_PREV:
2218 case OP_SIDEBAR_NEXT_NEW:
2219 case OP_SIDEBAR_PREV_NEW:
2220 sidebar_scroll (op);
2223 if (menu->menu == MENU_MAIN)
2224 km_error_key (MENU_MAIN);
2227 if (menu->menu == MENU_PAGER) {
2228 menu->menu = MENU_MAIN;
2229 menu->redraw = REDRAW_FULL;
2237 /* Close all open IMAP connections */
2240 /* Close all open NNTP connections */
2245 mutt_menuDestroy (&menu);
2249 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2256 for (color = ColorIndexList; color; color = color->next)
2257 if (mutt_pattern_exec
2258 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2259 curhdr->pair = color->pair;
2262 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];