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)
90 extern size_t UngetCount;
92 void index_make_entry (char *s, ssize_t l, struct menu_t * menu, int num)
94 format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_INDEX;
95 int edgemsgno, reverse = Sort & SORT_REVERSE;
96 HEADER *h = Context->hdrs[Context->v2r[num]];
99 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree) {
100 flag |= M_FORMAT_TREE; /* display the thread tree */
101 if (h->display_subject)
102 flag |= M_FORMAT_FORCESUBJ;
105 if (menu->top + menu->pagelen > menu->max)
106 edgemsgno = Context->v2r[menu->max - 1];
108 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
111 edgemsgno = Context->v2r[menu->top];
113 for (tmp = h->thread->parent; tmp; tmp = tmp->parent) {
117 /* if no ancestor is visible on current screen, provisionally force
119 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno <
121 flag |= M_FORMAT_FORCESUBJ;
124 else if (tmp->message->virtual >= 0)
127 if (flag & M_FORMAT_FORCESUBJ) {
128 for (tmp = h->thread->prev; tmp; tmp = tmp->prev) {
132 /* ...but if a previous sibling is available, don't force it */
133 if (reverse ? tmp->message->msgno >
134 edgemsgno : tmp->message->msgno < edgemsgno)
136 else if (tmp->message->virtual >= 0) {
137 flag &= ~M_FORMAT_FORCESUBJ;
145 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
148 int index_color (int index_no)
150 HEADER *h = Context->hdrs[Context->v2r[index_no]];
155 mutt_set_header_color (Context, h);
159 static int ci_next_undeleted (int msgno)
163 for (i = msgno + 1; i < Context->vcount; i++)
164 if (!Context->hdrs[Context->v2r[i]]->deleted)
169 static int ci_previous_undeleted (int msgno)
173 for (i = msgno - 1; i >= 0; i--)
174 if (!Context->hdrs[Context->v2r[i]]->deleted)
179 /* Return the index of the first new message, or failing that, the first
182 static int ci_first_message (void)
186 if (Context && Context->msgcount) {
187 for (i = 0; i < Context->vcount; i++) {
188 if (!Context->hdrs[Context->v2r[i]]->read &&
189 !Context->hdrs[Context->v2r[i]]->deleted) {
190 if (!Context->hdrs[Context->v2r[i]]->old)
199 /* If Sort is reverse and not threaded, the latest message is first.
200 * If Sort is threaded, the latest message is first iff exactly one
201 * of Sort and SortAux are reverse.
203 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
204 ((Sort & SORT_MASK) == SORT_THREADS &&
205 ((Sort ^ SortAux) & SORT_REVERSE)))
208 return (Context->vcount ? Context->vcount - 1 : 0);
213 /* This should be in mx.c, but it only gets used here. */
214 static int mx_toggle_write (CONTEXT * ctx)
220 mutt_error (_("Cannot toggle write on a readonly mailbox!"));
225 if (ctx->dontwrite) {
227 mutt_message (_("Changes to folder will be written on folder exit."));
231 mutt_message (_("Changes to folder will not be written."));
237 static void update_index (MUTTMENU * menu, CONTEXT * ctx __attribute__ ((unused)), int check,
238 int oldcount, int index_hint)
240 /* store pointers to the newly added messages */
241 HEADER **save_new = NULL;
244 /* take note of the current message */
246 if (menu->current < Context->vcount)
247 menu->oldcurrent = index_hint;
249 oldcount = 0; /* invalid message number! */
252 /* We are in a limited view. Check if the new message(s) satisfy
253 * the limit criteria. If they do, set their virtual msgno so that
254 * they will be visible in the limited view */
255 if (Context->pattern) {
256 #define THIS_BODY Context->hdrs[j]->content
257 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++) {
258 if (mutt_pattern_exec
259 (Context->limit_pattern, M_MATCH_FULL_ADDRESS, Context,
261 Context->hdrs[j]->virtual = Context->vcount;
262 Context->v2r[Context->vcount] = j;
263 Context->hdrs[j]->limited = 1;
266 THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
272 /* save the list of new messages */
273 if (oldcount && check != M_REOPENED && ((Sort & SORT_MASK) == SORT_THREADS)) {
274 save_new = p_new(HEADER*, Context->msgcount - oldcount);
275 for (j = oldcount; j < Context->msgcount; j++)
276 save_new[j - oldcount] = Context->hdrs[j];
279 /* if the mailbox was reopened, need to rethread from scratch */
280 mutt_sort_headers (Context, (check == M_REOPENED));
282 /* uncollapse threads with new mail */
283 if ((Sort & SORT_MASK) == SORT_THREADS) {
284 if (check == M_REOPENED) {
287 Context->collapsed = 0;
289 for (h = Context->tree; h; h = h->next) {
290 for (c = h; !c->message; c = c->child);
291 mutt_uncollapse_thread (Context, c->message);
293 mutt_set_virtual (Context);
296 for (j = 0; j < Context->msgcount - oldcount; j++) {
299 for (k = 0; k < Context->msgcount; k++) {
300 HEADER *h = Context->hdrs[k];
302 if (h == save_new[j] && (!Context->pattern || h->limited))
303 mutt_uncollapse_thread (Context, h);
307 mutt_set_virtual (Context);
313 /* restore the current message to the message it was pointing to */
314 for (j = 0; j < Context->vcount; j++) {
315 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent) {
322 if (menu->current < 0)
323 menu->current = ci_first_message ();
326 static void resort_index (MUTTMENU * menu)
329 HEADER *current = CURHDR;
332 mutt_sort_headers (Context, 0);
333 /* Restore the current message */
335 for (i = 0; i < Context->vcount; i++) {
336 if (Context->hdrs[Context->v2r[i]] == current) {
342 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
343 menu->current = mutt_parent_message (Context, current);
345 if (menu->current < 0)
346 menu->current = ci_first_message ();
348 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
351 /* This function handles the message index window as well as commands returned
352 * from the pager (MENU_PAGER).
354 int mutt_index_menu (void)
356 char buf[LONG_STRING];
359 int done = 0; /* controls when to exit the "event" loop */
361 int tag = 0; /* has the tag-prefix command been pressed? */
366 const char *cp; /* temporary variable. */
367 int index_hint; /* used to restore cursor position */
368 int do_buffy_notify = 1;
369 int closed = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
370 int attach_msg = option (OPTATTACHMSG);
372 menu = mutt_new_menu ();
373 menu->menu = MENU_MAIN;
375 menu->pagelen = LINES - 3;
376 menu->make_entry = (void *) index_make_entry;
377 menu->color = index_color;
378 menu->current = ci_first_message ();
381 buffy_check (0); /* force the buffy check after we enter the folder */
382 /* record folder we open to place sidebar indicator properly */
383 if (Context && Context->path)
384 sidebar_set_current (Context->path);
388 tag = 0; /* clear the tag-prefix */
390 menu->max = Context ? Context->vcount : 0;
391 oldcount = Context ? Context->msgcount : 0;
393 /* check if we need to resort the index because just about
394 * any 'op' below could do mutt_enter_command(), either here or
395 * from any new menu launched, and change $sort/$sort_aux
397 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
400 if (option (OPTREDRAWTREE) && Context && Context->msgcount
401 && (Sort & SORT_MASK) == SORT_THREADS) {
402 mutt_draw_tree (Context);
403 menu->redraw |= REDRAW_STATUS;
404 unset_option (OPTREDRAWTREE);
407 if (Context && !attach_msg) {
410 /* check for new mail in the mailbox. If nonzero, then something has
411 * changed about the file (either we got new mail or the file was
412 * modified underneath us.)
415 imap_allow_reopen (Context);
417 index_hint = (Context->vcount && menu->current >= 0
418 && menu->current < Context->vcount) ? CURHDR->index : 0;
420 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) {
421 if (!Context->path) {
422 /* fatal error occurred */
424 menu->redraw = REDRAW_FULL;
426 set_option (OPTSEARCHINVALID);
428 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS) {
429 update_index (menu, Context, check, oldcount, index_hint);
431 /* notify the user of new mail */
432 if (check == M_REOPENED)
434 ("Mailbox was externally modified. Flags may be wrong."));
435 else if (check == M_NEW_MAIL) {
436 /* on new mail: redraw sidebar */
438 mutt_message (_("New mail in this mailbox."));
440 if (mod_core.beep_new)
443 else if (check == M_FLAGS)
444 mutt_message (_("Mailbox was externally modified."));
446 /* avoid the message being overwritten by buffy */
449 menu->redraw = REDRAW_FULL;
450 menu->max = Context->vcount;
452 set_option (OPTSEARCHINVALID);
457 imap_disallow_reopen (Context);
460 /* check for new mail in the incoming folders */
462 if ((newcount = buffy_check (0)) != oldcount) {
463 menu->redraw |= REDRAW_STATUS;
464 menu->redraw |= REDRAW_SIDEBAR;
466 if (do_buffy_notify) {
467 if (buffy_notify () && mod_core.beep_new)
476 if (menu->redraw & REDRAW_SIDEBAR)
478 if (menu->redraw & REDRAW_FULL) {
479 menu_redraw_full (menu);
484 if (menu->menu == MENU_MAIN) {
485 if (Context && Context->hdrs && !(menu->current >= Context->vcount)) {
486 menu_check_recenter (menu);
488 if (menu->redraw & REDRAW_INDEX) {
489 menu_redraw_index (menu);
490 menu->redraw |= REDRAW_STATUS;
492 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
493 menu_redraw_motion (menu);
494 else if (menu->redraw & REDRAW_CURRENT)
495 menu_redraw_current (menu);
498 if (menu->redraw & REDRAW_STATUS) {
499 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
500 CLEARLINE(main_w, option (OPTSTATUSONTOP) ? 0 : LINES - 2);
501 SETCOLOR(main_w, MT_COLOR_STATUS);
502 BKGDSET(main_w, MT_COLOR_STATUS);
503 wmove(main_w, option (OPTSTATUSONTOP) ? 0 : LINES - 2, 0);
504 mutt_paddstr (main_w, getmaxx(main_w), buf);
505 SETCOLOR(main_w, MT_COLOR_NORMAL);
506 BKGDSET(main_w, MT_COLOR_NORMAL);
507 sidebar_set_buffystats (Context);
508 menu->redraw &= ~REDRAW_STATUS;
509 if (option (OPTXTERMSETTITLES)) {
510 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermTitle));
511 printf("\033]2;%s\007", buf);
512 menu_status_line(buf, sizeof(buf), menu, NONULL(XtermIcon));
513 printf("\033]1;%s\007", buf);
519 if (menu->current < menu->max)
520 menu->oldcurrent = menu->current;
522 menu->oldcurrent = -1;
528 menu->redraw = REDRAW_FULL;
529 menu->menu = MENU_MAIN;
530 menu->top = 0; /* so we scroll the right amount */
534 op = km_dokey (MENU_MAIN);
536 continue; /* either user abort or timeout */
540 /* special handling for the tag-prefix function */
541 if (op == OP_TAG_PREFIX) {
543 mutt_error (_("No mailbox is open."));
548 if (!Context->tagged) {
549 mutt_error (_("No tagged messages."));
555 /* give visual indication that the next command is a tag- command */
556 mvwaddstr (main_w, LINES - 1, 0, "tag-");
559 /* get the real command */
560 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
561 /* abort tag sequence */
562 CLEARLINE(main_w, LINES - 1);
566 else if (option (OPTAUTOTAG) && Context && Context->tagged)
569 if (op == OP_TAG_PREFIX_COND) {
571 mutt_error (_("No mailbox is open."));
576 if (!Context->tagged) {
579 while (UngetCount > 0) {
581 if (tmp.op == OP_END_COND)
584 mutt_message (_("Nothing to do."));
590 /* give visual indication that the next command is a tag- command */
591 mvwaddstr (main_w, LINES - 1, 0, "tag-");
594 /* get the real command */
595 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX) {
596 /* abort tag sequence */
597 CLEARLINE(main_w, LINES - 1);
605 if (menu->current < menu->max)
606 menu->oldcurrent = menu->current;
608 menu->oldcurrent = -1;
610 mutt_curs_set (1); /* fallback from the pager */
614 unset_option (OPTNEWS); /* for any case */
619 /* ----------------------------------------------------------------------
624 menu_bottom_page (menu);
627 menu_first_entry (menu);
630 menu_middle_page (menu);
636 menu_half_down (menu);
639 menu_next_line (menu);
642 menu_prev_line (menu);
645 menu_next_page (menu);
648 menu_prev_page (menu);
651 menu_last_entry (menu);
654 menu_top_page (menu);
657 menu_current_top (menu);
659 case OP_CURRENT_MIDDLE:
660 menu_current_middle (menu);
662 case OP_CURRENT_BOTTOM:
663 menu_current_bottom (menu);
670 if (Context->magic == M_NNTP) {
673 if (op == OP_GET_MESSAGE) {
675 if (mutt_get_field (_("Enter Message-ID: "), buf, sizeof (buf), 0)
680 string_list_t *ref = CURHDR->env->references;
683 mutt_error (_("Article has no parent reference!"));
687 m_strcpy(buf, sizeof(buf), ref->data);
689 if (!Context->id_hash)
690 Context->id_hash = mutt_make_id_hash (Context);
691 if ((h = hash_find (Context->id_hash, buf))) {
692 if (h->virtual != -1) {
693 menu->current = h->virtual;
694 menu->redraw = REDRAW_MOTION_RESYNCH;
696 else if (h->collapsed) {
697 mutt_uncollapse_thread (Context, h);
698 mutt_set_virtual (Context);
699 menu->current = h->virtual;
700 menu->redraw = REDRAW_MOTION_RESYNCH;
703 mutt_error (_("Message not visible in limited view."));
706 if (nntp_check_msgid (Context, buf) == 0) {
707 h = Context->hdrs[Context->msgcount - 1];
708 mutt_sort_headers (Context, 0);
709 menu->current = h->virtual;
710 menu->redraw = REDRAW_FULL;
713 mutt_error (_("Article %s not found on server"), buf);
718 case OP_GET_CHILDREN:
719 case OP_RECONSTRUCT_THREAD:
721 if (Context->magic == M_NNTP) {
723 int old = CURHDR->index;
725 if (!CURHDR->env->message_id) {
726 mutt_error (_("No Message-ID. Unable to perform operation"));
731 if (!Context->id_hash)
732 Context->id_hash = mutt_make_id_hash (Context);
733 m_strcpy(buf, sizeof(buf), CURHDR->env->message_id);
735 if (op == OP_RECONSTRUCT_THREAD) {
736 string_list_t *ref = CURHDR->env->references;
739 nntp_check_msgid (Context, ref->data);
740 /* the last msgid in References is the root message */
742 m_strcpy(buf, sizeof(buf), ref->data);
746 mutt_message (_("Check for children of message..."));
748 if (nntp_check_children (Context, buf) == 0) {
749 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
750 h = hash_find (Context->id_hash, buf);
751 /* if the root message was retrieved, move to it */
753 menu->current = h->virtual;
754 else /* try to restore old position */
755 for (i = 0; i < Context->msgcount; i++)
756 if (Context->hdrs[i]->index == old) {
757 menu->current = Context->hdrs[i]->virtual;
758 /* As an added courtesy, recenter the menu
759 * with the current entry at the middle of the screen */
760 menu_check_recenter (menu);
761 menu_current_middle (menu);
764 menu->redraw = REDRAW_FULL;
774 if (isdigit (LastKey))
775 mutt_ungetch (LastKey, 0);
777 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
781 if (!isdigit ((unsigned char) buf[0])) {
782 mutt_error (_("Argument must be a message number."));
788 if (i > 0 && i <= Context->msgcount) {
789 for (j = i - 1; j < Context->msgcount; j++) {
790 if (Context->hdrs[j]->virtual != -1)
793 if (j >= Context->msgcount) {
794 for (j = i - 2; j >= 0; j--) {
795 if (Context->hdrs[j]->virtual != -1)
801 menu->current = Context->hdrs[j]->virtual;
802 if (menu->menu == MENU_PAGER) {
803 op = OP_DISPLAY_MESSAGE;
807 menu->redraw = REDRAW_MOTION;
810 mutt_error (_("That message is not visible."));
813 mutt_error (_("Invalid message number."));
817 /* --------------------------------------------------------------------
818 * `index' specific commands
821 case OP_MAIN_DELETE_PATTERN:
827 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
830 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
831 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
834 case OP_MAIN_FETCH_MAIL:
838 menu->redraw = REDRAW_FULL;
843 mutt_help (MENU_MAIN);
844 menu->redraw = REDRAW_FULL;
847 case OP_MAIN_SHOW_LIMIT:
849 if (!Context->pattern)
850 mutt_message (_("No limit pattern is in effect."));
855 /* i18n: ask for a limit to apply */
856 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
857 mutt_message ("%s", buffer);
865 menu->oldcurrent = (Context->vcount && menu->current >= 0
867 Context->vcount) ? CURHDR->index : -1;
868 if (op == OP_TOGGLE_READ) {
869 char buffer[LONG_STRING];
871 if (m_strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
872 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
873 Context->pattern ? Context->pattern : ".*");
874 set_option (OPTHIDEREAD);
877 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
878 if (m_strncmp (buf, ".*", 2) == 0)
879 snprintf (buf, sizeof (buf), "~A");
880 unset_option (OPTHIDEREAD);
882 p_delete(&Context->pattern);
883 Context->pattern = m_strdup(buf);
885 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
886 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
888 if (menu->oldcurrent >= 0) {
889 /* try to find what used to be the current message */
891 for (i = 0; i < Context->vcount; i++)
892 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
896 if (menu->current < 0)
901 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
902 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
903 mutt_draw_tree (Context);
904 menu->redraw = REDRAW_FULL;
906 if (Context->pattern)
907 mutt_message _("To view all messages, limit to \"all\".");
918 if (query_quadoption2(mod_core.quit, _("Quit Madmutt?")) == M_YES) {
921 oldcount = Context ? Context->msgcount : 0;
924 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
927 if (check == M_NEW_MAIL || check == M_REOPENED)
928 update_index (menu, Context, check, oldcount, index_hint);
930 menu->redraw = REDRAW_FULL; /* new mail arrived? */
931 set_option (OPTSEARCHINVALID);
937 clearok (main_w, TRUE);
938 menu->redraw = REDRAW_FULL;
942 case OP_SEARCH_REVERSE:
944 case OP_SEARCH_OPPOSITE:
948 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
949 menu->current = menu->oldcurrent;
951 menu->redraw = REDRAW_MOTION;
955 case OP_SORT_REVERSE:
957 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
958 if (Context && Context->msgcount) {
960 set_option (OPTSEARCHINVALID);
969 if (tag && !option (OPTAUTOTAG)) {
970 for (j = 0; j < Context->vcount; j++)
971 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
972 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
975 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
976 Context->last_tag = CURHDR->tagged ? CURHDR :
977 ((Context->last_tag == CURHDR && !CURHDR->tagged)
978 ? NULL : Context->last_tag);
979 menu->redraw = REDRAW_STATUS;
980 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
982 menu->redraw |= REDRAW_MOTION_RESYNCH;
985 menu->redraw |= REDRAW_CURRENT;
989 case OP_MAIN_TAG_PATTERN:
993 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
994 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
997 case OP_MAIN_UNDELETE_PATTERN:
1003 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
1005 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
1007 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1010 case OP_MAIN_UNTAG_PATTERN:
1014 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1015 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1018 /* --------------------------------------------------------------------
1019 * The following operations can be performed inside of the pager.
1022 case OP_MAIN_IMAP_FETCH:
1023 if (Context->magic == M_IMAP)
1024 imap_check_mailbox (Context, &index_hint, 1);
1027 case OP_MAIN_SYNC_FOLDER:
1029 if (Context && !Context->msgcount)
1036 int oldvcount = Context->vcount;
1037 oldcount = Context->msgcount;
1041 /* calculate the number of messages _above_ the cursor,
1042 * so we can keep the cursor on the current message
1044 for (j = 0; j <= menu->current; j++) {
1045 if (Context->hdrs[Context->v2r[j]]->deleted)
1049 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1050 if (Context->vcount != oldvcount)
1051 menu->current -= dcount;
1052 set_option (OPTSEARCHINVALID);
1054 else if (check == M_NEW_MAIL || check == M_REOPENED)
1055 update_index (menu, Context, check, oldcount, index_hint);
1058 * do a sanity check even if mx_sync_mailbox failed.
1061 if (menu->current < 0 || menu->current >= Context->vcount)
1062 menu->current = ci_first_message ();
1065 /* check for a fatal error, or all messages deleted */
1069 /* if we were in the pager, redisplay the message */
1070 if (menu->menu == MENU_PAGER) {
1071 op = OP_DISPLAY_MESSAGE;
1075 menu->redraw = REDRAW_FULL;
1078 case OP_SIDEBAR_OPEN:
1079 case OP_MAIN_CHANGE_FOLDER:
1080 case OP_MAIN_CHANGE_FOLDER_READONLY:
1082 case OP_MAIN_CHANGE_GROUP:
1083 case OP_MAIN_CHANGE_GROUP_READONLY:
1085 if (attach_msg || option (OPTREADONLY) ||
1087 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1089 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1095 cp = _("Open mailbox in read-only mode");
1097 cp = _("Open mailbox");
1101 unset_option (OPTNEWS);
1102 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1103 set_option (OPTNEWS);
1104 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1107 cp = _("Open newsgroup in read-only mode");
1109 cp = _("Open newsgroup");
1110 nntp_buffy (buf, sizeof (buf));
1115 if (Context && Context->path)
1116 m_strcpy(buf, sizeof(buf), Context->path);
1117 if (op != OP_SIDEBAR_OPEN)
1118 buffy_next (buf, sizeof (buf));
1121 if (op == OP_SIDEBAR_OPEN) {
1122 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1124 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1125 if (menu->menu == MENU_PAGER) {
1126 op = OP_DISPLAY_MESSAGE;
1132 CLEARLINE(main_w, LINES - 1);
1137 if (option (OPTNEWS)) {
1138 unset_option (OPTNEWS);
1139 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1143 mutt_expand_path (buf, sizeof (buf));
1144 if (mx_get_magic (buf) <= 0) {
1145 mutt_error (_("%s is not a mailbox."), buf);
1148 m_strreplace(&CurrentFolder, buf);
1153 if (Context->cinfo && Context->realpath)
1154 m_strreplace(&LastFolder, Context->realpath);
1156 m_strreplace(&LastFolder, Context->path);
1157 oldcount = Context ? Context->msgcount : 0;
1159 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1160 if (check == M_NEW_MAIL || check == M_REOPENED)
1161 update_index (menu, Context, check, oldcount, index_hint);
1163 set_option (OPTSEARCHINVALID);
1164 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1172 /* Set CurrentMenu to MENU_MAIN before executing any folder
1173 * hooks so that all the index menu functions are available to
1177 CurrentMenu = MENU_MAIN;
1178 mutt_folder_hook (buf);
1180 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1181 menu->current = ci_first_message ();
1185 sidebar_set_current (buf);
1187 mutt_clear_error ();
1188 buffy_check (0); /* force the buffy check after we have changed
1190 menu->redraw = REDRAW_FULL;
1191 set_option (OPTSEARCHINVALID);
1194 case OP_DISPLAY_MESSAGE:
1195 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1200 * toggle the weeding of headers so that a user can press the key
1201 * again while reading the message.
1203 if (op == OP_DISPLAY_HEADERS)
1204 toggle_option (OPTWEED);
1206 unset_option (OPTNEEDRESORT);
1208 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1209 mutt_uncollapse_thread (Context, CURHDR);
1210 mutt_set_virtual (Context);
1211 if (option (OPTUNCOLLAPSEJUMP))
1212 menu->current = mutt_thread_next_unread (Context, CURHDR);
1215 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1216 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1218 if ((op = mutt_display_message (CURHDR)) == -1) {
1219 unset_option (OPTNEEDRESORT);
1223 menu->menu = MENU_PAGER;
1224 menu->oldcurrent = menu->current;
1230 if (menu->menu == MENU_MAIN && attach_msg) {
1235 if ((menu->menu == MENU_MAIN)
1236 && (query_quadoption2(mod_core.quit,
1237 _("Exit Madmutt without saving?")) == M_YES))
1240 mx_fastclose_mailbox (Context);
1252 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1253 /* if we were in the pager, redisplay the message */
1254 if (menu->menu == MENU_PAGER) {
1255 op = OP_DISPLAY_MESSAGE;
1259 menu->redraw = REDRAW_CURRENT;
1262 case OP_MAIN_BREAK_THREAD:
1268 if ((Sort & SORT_MASK) != SORT_THREADS)
1269 mutt_error (_("Threading is not enabled."));
1273 HEADER *oldcur = CURHDR;
1275 mutt_break_thread (CURHDR);
1276 mutt_sort_headers (Context, 1);
1277 menu->current = oldcur->virtual;
1280 Context->changed = 1;
1281 mutt_message _("Thread broken");
1283 if (menu->menu == MENU_PAGER) {
1284 op = OP_DISPLAY_MESSAGE;
1288 menu->redraw |= REDRAW_INDEX;
1292 case OP_MAIN_LINK_THREADS:
1298 if ((Sort & SORT_MASK) != SORT_THREADS)
1299 mutt_error (_("Threading is not enabled."));
1301 else if (!CURHDR->env->message_id)
1302 mutt_error (_("No Message-ID: header available to link thread"));
1304 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1305 mutt_error (_("First, please tag a message to be linked here"));
1308 HEADER *oldcur = CURHDR;
1310 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1312 mutt_sort_headers (Context, 1);
1313 menu->current = oldcur->virtual;
1315 Context->changed = 1;
1316 mutt_message _("Threads linked");
1319 mutt_error (_("No thread linked"));
1322 if (menu->menu == MENU_PAGER) {
1323 op = OP_DISPLAY_MESSAGE;
1327 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1330 case OP_MAIN_NEXT_UNDELETED:
1334 if (menu->current >= Context->vcount - 1) {
1335 if (menu->menu == MENU_MAIN)
1336 mutt_error (_("You are on the last message."));
1340 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1341 menu->current = menu->oldcurrent;
1342 if (menu->menu == MENU_MAIN)
1343 mutt_error (_("No undeleted messages."));
1345 else if (menu->menu == MENU_PAGER) {
1346 op = OP_DISPLAY_MESSAGE;
1350 menu->redraw = REDRAW_MOTION;
1357 if (menu->current >= Context->vcount - 1) {
1358 if (menu->menu == MENU_MAIN)
1359 mutt_error (_("You are on the last message."));
1364 if (menu->menu == MENU_PAGER) {
1365 op = OP_DISPLAY_MESSAGE;
1369 menu->redraw = REDRAW_MOTION;
1372 case OP_MAIN_PREV_UNDELETED:
1376 if (menu->current < 1) {
1377 mutt_error (_("You are on the first message."));
1381 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1382 menu->current = menu->oldcurrent;
1383 if (menu->menu == MENU_MAIN)
1384 mutt_error (_("No undeleted messages."));
1386 else if (menu->menu == MENU_PAGER) {
1387 op = OP_DISPLAY_MESSAGE;
1391 menu->redraw = REDRAW_MOTION;
1398 if (menu->current < 1) {
1399 if (menu->menu == MENU_MAIN)
1400 mutt_error (_("You are on the first message."));
1405 if (menu->menu == MENU_PAGER) {
1406 op = OP_DISPLAY_MESSAGE;
1410 menu->redraw = REDRAW_MOTION;
1413 case OP_DECRYPT_COPY:
1414 case OP_DECRYPT_SAVE:
1415 case OP_COPY_MESSAGE:
1417 case OP_DECODE_COPY:
1418 case OP_DECODE_SAVE:
1421 if (mutt_save_message (tag ? NULL : CURHDR,
1422 (op == OP_DECRYPT_SAVE) ||
1423 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1424 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1425 (op == OP_DECRYPT_SAVE)
1426 || (op == OP_DECRYPT_COPY)
1427 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1434 menu->redraw |= REDRAW_INDEX;
1435 else if (option (OPTRESOLVE)) {
1436 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1437 menu->current = menu->oldcurrent;
1438 menu->redraw |= REDRAW_CURRENT;
1441 menu->redraw |= REDRAW_MOTION_RESYNCH;
1444 menu->redraw |= REDRAW_CURRENT;
1448 case OP_MAIN_NEXT_NEW:
1449 case OP_MAIN_NEXT_UNREAD:
1450 case OP_MAIN_PREV_NEW:
1451 case OP_MAIN_PREV_UNREAD:
1452 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1453 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1456 int first_unread = -1;
1464 for (j = 0; j != Context->vcount; j++) {
1465 #define CURHDRi Context->hdrs[Context->v2r[i]]
1466 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1467 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1469 if (i > Context->vcount - 1) {
1470 mutt_message _("Search wrapped to top.");
1478 mutt_message _("Search wrapped to bottom.");
1480 i = Context->vcount - 1;
1484 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1485 if (UNREAD (CURHDRi) && first_unread == -1)
1487 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1490 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1491 if (first_unread == -1)
1493 if ((!CURHDRi->old) && first_new == -1)
1497 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1500 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1501 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1502 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1507 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1508 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1509 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1511 menu->current = first_new;
1512 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1513 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1514 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1515 && first_unread != -1)
1516 menu->current = first_unread;
1518 if (menu->current == -1) {
1519 menu->current = menu->oldcurrent;
1520 mutt_error ("%s%s.",
1521 (op == OP_MAIN_NEXT_NEW
1523 OP_MAIN_PREV_NEW) ? _("No new messages") :
1524 _("No unread messages"),
1525 Context->pattern ? _(" in this limited view") : "");
1527 else if (menu->menu == MENU_PAGER) {
1528 op = OP_DISPLAY_MESSAGE;
1532 menu->redraw = REDRAW_MOTION;
1535 case OP_FLAG_MESSAGE:
1541 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1544 for (j = 0; j < Context->vcount; j++) {
1545 if (Context->hdrs[Context->v2r[j]]->tagged)
1546 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1547 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1550 menu->redraw |= REDRAW_INDEX;
1553 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1554 if (option (OPTRESOLVE)) {
1555 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1556 menu->current = menu->oldcurrent;
1557 menu->redraw = REDRAW_CURRENT;
1560 menu->redraw = REDRAW_MOTION_RESYNCH;
1563 menu->redraw = REDRAW_CURRENT;
1565 menu->redraw |= REDRAW_STATUS;
1574 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1577 for (j = 0; j < Context->vcount; j++) {
1578 if (Context->hdrs[Context->v2r[j]]->tagged) {
1579 if (Context->hdrs[Context->v2r[j]]->read ||
1580 Context->hdrs[Context->v2r[j]]->old)
1581 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1584 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1588 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1591 if (CURHDR->read || CURHDR->old)
1592 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1594 mutt_set_flag (Context, CURHDR, M_READ, 1);
1596 if (option (OPTRESOLVE)) {
1597 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1598 menu->current = menu->oldcurrent;
1599 menu->redraw = REDRAW_CURRENT;
1602 menu->redraw = REDRAW_MOTION_RESYNCH;
1605 menu->redraw = REDRAW_CURRENT;
1606 menu->redraw |= REDRAW_STATUS;
1610 case OP_TOGGLE_WRITE:
1613 if (mx_toggle_write (Context) == 0)
1614 menu->redraw |= REDRAW_STATUS;
1617 case OP_MAIN_NEXT_THREAD:
1618 case OP_MAIN_NEXT_SUBTHREAD:
1619 case OP_MAIN_PREV_THREAD:
1620 case OP_MAIN_PREV_SUBTHREAD:
1625 case OP_MAIN_NEXT_THREAD:
1626 menu->current = mutt_next_thread (CURHDR);
1629 case OP_MAIN_NEXT_SUBTHREAD:
1630 menu->current = mutt_next_subthread (CURHDR);
1633 case OP_MAIN_PREV_THREAD:
1634 menu->current = mutt_previous_thread (CURHDR);
1637 case OP_MAIN_PREV_SUBTHREAD:
1638 menu->current = mutt_previous_subthread (CURHDR);
1642 if (menu->current < 0) {
1643 menu->current = menu->oldcurrent;
1644 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1645 mutt_error (_("No more threads."));
1648 mutt_error (_("You are on the first thread."));
1650 else if (menu->menu == MENU_PAGER) {
1651 op = OP_DISPLAY_MESSAGE;
1655 menu->redraw = REDRAW_MOTION;
1658 case OP_MAIN_PARENT_MESSAGE:
1663 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1664 menu->current = menu->oldcurrent;
1666 else if (menu->menu == MENU_PAGER) {
1667 op = OP_DISPLAY_MESSAGE;
1671 menu->redraw = REDRAW_MOTION;
1674 case OP_MAIN_SET_FLAG:
1675 case OP_MAIN_CLEAR_FLAG:
1681 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0) {
1682 menu->redraw = REDRAW_STATUS;
1684 menu->redraw |= REDRAW_INDEX;
1685 else if (option (OPTRESOLVE)) {
1686 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1687 menu->current = menu->oldcurrent;
1688 menu->redraw |= REDRAW_CURRENT;
1691 menu->redraw |= REDRAW_MOTION_RESYNCH;
1694 menu->redraw |= REDRAW_CURRENT;
1698 case OP_MAIN_COLLAPSE_THREAD:
1702 if ((Sort & SORT_MASK) != SORT_THREADS) {
1703 mutt_error (_("Threading is not enabled."));
1708 if (CURHDR->collapsed) {
1709 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1710 mutt_set_virtual (Context);
1711 if (option (OPTUNCOLLAPSEJUMP))
1712 menu->current = mutt_thread_next_unread (Context, CURHDR);
1714 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1715 menu->current = mutt_collapse_thread (Context, CURHDR);
1716 mutt_set_virtual (Context);
1719 mutt_error (_("Thread contains unread messages."));
1724 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1728 case OP_MAIN_COLLAPSE_ALL:
1732 if ((Sort & SORT_MASK) != SORT_THREADS) {
1733 mutt_error (_("Threading is not enabled."));
1740 THREAD *thread, *top;
1743 if (CURHDR->collapsed)
1744 final = mutt_uncollapse_thread (Context, CURHDR);
1745 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1746 final = mutt_collapse_thread (Context, CURHDR);
1748 final = CURHDR->virtual;
1750 base = Context->hdrs[Context->v2r[final]];
1752 top = Context->tree;
1753 Context->collapsed = !Context->collapsed;
1754 while ((thread = top) != NULL) {
1755 while (!thread->message)
1756 thread = thread->child;
1757 h = thread->message;
1759 if (h->collapsed != Context->collapsed) {
1761 mutt_uncollapse_thread (Context, h);
1762 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1763 mutt_collapse_thread (Context, h);
1768 mutt_set_virtual (Context);
1769 for (j = 0; j < Context->vcount; j++) {
1770 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1776 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1780 /* --------------------------------------------------------------------
1781 * These functions are invoked directly from the internal-pager
1784 case OP_BOUNCE_MESSAGE:
1789 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1792 case OP_CREATE_ALIAS:
1794 mutt_create_alias (Context
1795 && Context->vcount ? CURHDR->env : NULL, NULL);
1796 MAYBE_REDRAW (menu->redraw);
1797 menu->redraw |= REDRAW_CURRENT;
1802 mutt_query_menu (NULL, 0);
1803 MAYBE_REDRAW (menu->redraw);
1806 case OP_PURGE_MESSAGE:
1813 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1816 mutt_tag_set_flag (M_DELETE, 1);
1817 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1818 if (option (OPTDELETEUNTAG))
1819 mutt_tag_set_flag (M_TAG, 0);
1820 menu->redraw = REDRAW_INDEX;
1823 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1824 mutt_set_flag (Context, CURHDR, M_PURGED,
1825 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1826 if (option (OPTDELETEUNTAG))
1827 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1828 if (option (OPTRESOLVE)) {
1829 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1830 menu->current = menu->oldcurrent;
1831 menu->redraw = REDRAW_CURRENT;
1833 else if (menu->menu == MENU_PAGER) {
1834 op = OP_DISPLAY_MESSAGE;
1838 menu->redraw |= REDRAW_MOTION_RESYNCH;
1841 menu->redraw = REDRAW_CURRENT;
1843 menu->redraw |= REDRAW_STATUS;
1846 case OP_DELETE_THREAD:
1847 case OP_DELETE_SUBTHREAD:
1853 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1855 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1856 op == OP_DELETE_THREAD ? 0 : 1);
1859 if (option (OPTDELETEUNTAG))
1860 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1861 op == OP_DELETE_THREAD ? 0 : 1);
1862 if (option (OPTRESOLVE))
1863 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1864 menu->current = menu->oldcurrent;
1865 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1871 if (Context && Context->magic == M_NNTP) {
1872 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1873 ((nntp_data_t *) Context->data)->group))
1874 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1879 case OP_DISPLAY_ADDRESS:
1883 mutt_display_address (CURHDR->env);
1886 case OP_ENTER_COMMAND:
1888 CurrentMenu = MENU_MAIN;
1889 mutt_enter_command ();
1890 mutt_check_rescore (Context);
1891 if (option (OPTFORCEREDRAWINDEX))
1892 menu->redraw = REDRAW_FULL;
1893 unset_option (OPTFORCEREDRAWINDEX);
1894 unset_option (OPTFORCEREDRAWPAGER);
1897 case OP_EDIT_MESSAGE:
1904 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1906 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1907 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1908 mutt_edit_message (Context, tag ? NULL : CURHDR);
1909 menu->redraw = REDRAW_FULL;
1913 case OP_FORWARD_MESSAGE:
1919 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1920 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1921 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
1922 menu->redraw = REDRAW_FULL;
1925 case OP_GROUP_REPLY:
1931 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1932 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1934 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
1935 tag ? NULL : CURHDR);
1936 menu->redraw = REDRAW_FULL;
1945 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1946 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1948 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
1949 tag ? NULL : CURHDR);
1950 menu->redraw = REDRAW_FULL;
1956 ci_send_message (0, NULL, NULL, Context, NULL);
1957 menu->redraw = REDRAW_FULL;
1960 case OP_EXTRACT_KEYS:
1963 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
1964 menu->redraw = REDRAW_FULL;
1968 case OP_CHECK_TRADITIONAL:
1971 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1972 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1974 if (menu->menu == MENU_PAGER) {
1975 op = OP_DISPLAY_MESSAGE;
1983 mutt_pipe_message (tag ? NULL : CURHDR);
1984 MAYBE_REDRAW (menu->redraw);
1990 mutt_print_message (tag ? NULL : CURHDR);
1993 case OP_MAIN_READ_THREAD:
1994 case OP_MAIN_READ_SUBTHREAD:
1999 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
2001 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2002 op == OP_MAIN_READ_THREAD ? 0 : 1);
2005 if (option (OPTRESOLVE)) {
2006 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2007 mutt_next_thread (CURHDR) :
2008 mutt_next_subthread (CURHDR))) == -1)
2009 menu->current = menu->oldcurrent;
2011 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2015 case OP_RECALL_MESSAGE:
2018 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2019 menu->redraw = REDRAW_FULL;
2029 for (j = 0; j < Context->vcount; j++) {
2030 if (Context->hdrs[Context->v2r[j]]->tagged)
2031 mutt_resend_message (NULL, Context,
2032 Context->hdrs[Context->v2r[j]]);
2036 mutt_resend_message (NULL, Context, CURHDR);
2038 menu->redraw = REDRAW_FULL;
2044 case OP_FORWARD_TO_GROUP:
2047 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2048 Context && Context->msgcount == 0) {
2049 mutt_error (_("There are no messages."));
2052 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2053 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2054 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2055 _("Reply by mail as poster prefers?")) !=
2057 if (Context && Context->magic == M_NNTP
2058 && !((nntp_data_t *) Context->data)->allowed
2059 && query_quadoption (OPT_TOMODERATED,
2061 ("Posting to this group not allowed, may be moderated. Continue?"))
2065 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2068 if (op == OP_FOLLOWUP)
2069 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2070 tag ? NULL : CURHDR);
2072 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2073 tag ? NULL : CURHDR);
2075 menu->redraw = REDRAW_FULL;
2086 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2087 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2089 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2090 menu->redraw = REDRAW_FULL;
2093 case OP_SHELL_ESCAPE:
2095 mutt_shell_escape ();
2096 MAYBE_REDRAW (menu->redraw);
2100 case OP_TAG_SUBTHREAD:
2104 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2105 op == OP_TAG_THREAD ? 0 : 1);
2108 if (option (OPTRESOLVE)) {
2109 menu->current = mutt_next_thread (CURHDR);
2111 if (menu->current == -1)
2112 menu->current = menu->oldcurrent;
2114 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2124 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2127 mutt_tag_set_flag (M_DELETE, 0);
2128 mutt_tag_set_flag (M_PURGED, 0);
2129 menu->redraw = REDRAW_INDEX;
2132 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2133 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2134 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2136 menu->redraw = REDRAW_MOTION_RESYNCH;
2139 menu->redraw = REDRAW_CURRENT;
2141 menu->redraw |= REDRAW_STATUS;
2144 case OP_UNDELETE_THREAD:
2145 case OP_UNDELETE_SUBTHREAD:
2151 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2153 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2154 op == OP_UNDELETE_THREAD ? 0 : 1)
2155 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2156 op == OP_UNDELETE_THREAD ? 0 : 1);
2159 if (option (OPTRESOLVE)) {
2160 if (op == OP_UNDELETE_THREAD)
2161 menu->current = mutt_next_thread (CURHDR);
2163 menu->current = mutt_next_subthread (CURHDR);
2165 if (menu->current == -1)
2166 menu->current = menu->oldcurrent;
2168 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2177 if (option (OPTFORCEBUFFYCHECK))
2180 menu->redraw = REDRAW_FULL;
2183 case OP_VIEW_ATTACHMENTS:
2186 mutt_view_attachments (CURHDR);
2187 if (CURHDR->attach_del)
2188 Context->changed = 1;
2189 menu->redraw = REDRAW_FULL;
2199 case OP_SIDEBAR_SCROLL_UP:
2200 case OP_SIDEBAR_SCROLL_DOWN:
2201 case OP_SIDEBAR_NEXT:
2202 case OP_SIDEBAR_PREV:
2203 case OP_SIDEBAR_NEXT_NEW:
2204 case OP_SIDEBAR_PREV_NEW:
2205 sidebar_scroll (op);
2208 if (menu->menu == MENU_MAIN)
2209 km_error_key (MENU_MAIN);
2212 if (menu->menu == MENU_PAGER) {
2213 menu->menu = MENU_MAIN;
2214 menu->redraw = REDRAW_FULL;
2222 /* Close all open IMAP connections */
2225 /* Close all open NNTP connections */
2230 mutt_menuDestroy (&menu);
2234 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2241 for (color = ColorIndexList; color; color = color->next)
2242 if (mutt_pattern_exec
2243 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2244 curhdr->pair = color->pair;
2247 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];