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, 0);
501 SETCOLOR(main_w, MT_COLOR_STATUS);
502 BKGDSET(main_w, MT_COLOR_STATUS);
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;
773 if (isdigit (LastKey))
774 mutt_ungetch (LastKey, 0);
776 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
780 if (!isdigit ((unsigned char) buf[0])) {
781 mutt_error (_("Argument must be a message number."));
787 if (i > 0 && i <= Context->msgcount) {
788 for (j = i - 1; j < Context->msgcount; j++) {
789 if (Context->hdrs[j]->virtual != -1)
792 if (j >= Context->msgcount) {
793 for (j = i - 2; j >= 0; j--) {
794 if (Context->hdrs[j]->virtual != -1)
800 menu->current = Context->hdrs[j]->virtual;
801 if (menu->menu == MENU_PAGER) {
802 op = OP_DISPLAY_MESSAGE;
806 menu->redraw = REDRAW_MOTION;
809 mutt_error (_("That message is not visible."));
812 mutt_error (_("Invalid message number."));
816 /* --------------------------------------------------------------------
817 * `index' specific commands
820 case OP_MAIN_DELETE_PATTERN:
825 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
828 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
829 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
832 case OP_MAIN_FETCH_MAIL:
835 menu->redraw = REDRAW_FULL;
839 mutt_help (MENU_MAIN);
840 menu->redraw = REDRAW_FULL;
843 case OP_MAIN_SHOW_LIMIT:
845 if (!Context->pattern)
846 mutt_message (_("No limit pattern is in effect."));
851 /* i18n: ask for a limit to apply */
852 snprintf (buffer, sizeof (buffer), _("Limit: %s"), Context->pattern);
853 mutt_message ("%s", buffer);
860 menu->oldcurrent = (Context->vcount && menu->current >= 0
862 Context->vcount) ? CURHDR->index : -1;
863 if (op == OP_TOGGLE_READ) {
864 char buffer[LONG_STRING];
866 if (m_strncmp (Context->pattern, "!~R!~D~s", 8) != 0) {
867 snprintf (buffer, sizeof (buffer), "!~R!~D~s%s",
868 Context->pattern ? Context->pattern : ".*");
869 set_option (OPTHIDEREAD);
872 m_strcpy(buf, sizeof(buf), Context->pattern + 8);
873 if (m_strncmp (buf, ".*", 2) == 0)
874 snprintf (buf, sizeof (buf), "~A");
875 unset_option (OPTHIDEREAD);
877 p_delete(&Context->pattern);
878 Context->pattern = m_strdup(buf);
880 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
881 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
883 if (menu->oldcurrent >= 0) {
884 /* try to find what used to be the current message */
886 for (i = 0; i < Context->vcount; i++)
887 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent) {
891 if (menu->current < 0)
896 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
897 if (Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
898 mutt_draw_tree (Context);
899 menu->redraw = REDRAW_FULL;
901 if (Context->pattern)
902 mutt_message _("To view all messages, limit to \"all\".");
912 if (query_quadoption2(mod_core.quit, _("Quit Madmutt?")) == M_YES) {
915 oldcount = Context ? Context->msgcount : 0;
918 || (check = mx_close_mailbox (Context, &index_hint)) == 0)
921 if (check == M_NEW_MAIL || check == M_REOPENED)
922 update_index (menu, Context, check, oldcount, index_hint);
924 menu->redraw = REDRAW_FULL; /* new mail arrived? */
925 set_option (OPTSEARCHINVALID);
931 clearok (main_w, TRUE);
932 menu->redraw = REDRAW_FULL;
936 case OP_SEARCH_REVERSE:
938 case OP_SEARCH_OPPOSITE:
941 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
942 menu->current = menu->oldcurrent;
944 menu->redraw = REDRAW_MOTION;
948 case OP_SORT_REVERSE:
949 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0) {
950 if (Context && Context->msgcount) {
952 set_option (OPTSEARCHINVALID);
960 if (tag && !option (OPTAUTOTAG)) {
961 for (j = 0; j < Context->vcount; j++)
962 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
963 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
966 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
967 Context->last_tag = CURHDR->tagged ? CURHDR :
968 ((Context->last_tag == CURHDR && !CURHDR->tagged)
969 ? NULL : Context->last_tag);
970 menu->redraw = REDRAW_STATUS;
971 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
973 menu->redraw |= REDRAW_MOTION_RESYNCH;
976 menu->redraw |= REDRAW_CURRENT;
980 case OP_MAIN_TAG_PATTERN:
983 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
984 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
987 case OP_MAIN_UNDELETE_PATTERN:
992 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
994 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) ==
996 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
999 case OP_MAIN_UNTAG_PATTERN:
1002 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1003 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1006 /* --------------------------------------------------------------------
1007 * The following operations can be performed inside of the pager.
1010 case OP_MAIN_IMAP_FETCH:
1011 if (Context->magic == M_IMAP)
1012 imap_check_mailbox (Context, &index_hint, 1);
1015 case OP_MAIN_SYNC_FOLDER:
1016 if (Context && !Context->msgcount)
1023 int oldvcount = Context->vcount;
1024 oldcount = Context->msgcount;
1028 /* calculate the number of messages _above_ the cursor,
1029 * so we can keep the cursor on the current message
1031 for (j = 0; j <= menu->current; j++) {
1032 if (Context->hdrs[Context->v2r[j]]->deleted)
1036 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0) {
1037 if (Context->vcount != oldvcount)
1038 menu->current -= dcount;
1039 set_option (OPTSEARCHINVALID);
1041 else if (check == M_NEW_MAIL || check == M_REOPENED)
1042 update_index (menu, Context, check, oldcount, index_hint);
1045 * do a sanity check even if mx_sync_mailbox failed.
1048 if (menu->current < 0 || menu->current >= Context->vcount)
1049 menu->current = ci_first_message ();
1052 /* check for a fatal error, or all messages deleted */
1056 /* if we were in the pager, redisplay the message */
1057 if (menu->menu == MENU_PAGER) {
1058 op = OP_DISPLAY_MESSAGE;
1062 menu->redraw = REDRAW_FULL;
1065 case OP_SIDEBAR_OPEN:
1066 case OP_MAIN_CHANGE_FOLDER:
1067 case OP_MAIN_CHANGE_FOLDER_READONLY:
1069 case OP_MAIN_CHANGE_GROUP:
1070 case OP_MAIN_CHANGE_GROUP_READONLY:
1074 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1076 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1082 cp = _("Open mailbox in read-only mode");
1084 cp = _("Open mailbox");
1088 unset_option (OPTNEWS);
1089 if (op == OP_MAIN_CHANGE_GROUP || op == OP_MAIN_CHANGE_GROUP_READONLY) {
1090 set_option (OPTNEWS);
1091 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1094 cp = _("Open newsgroup in read-only mode");
1096 cp = _("Open newsgroup");
1097 nntp_buffy (buf, sizeof (buf));
1102 if (Context && Context->path)
1103 m_strcpy(buf, sizeof(buf), Context->path);
1104 if (op != OP_SIDEBAR_OPEN)
1105 buffy_next (buf, sizeof (buf));
1108 if (op == OP_SIDEBAR_OPEN) {
1109 m_strcpy(buf, sizeof(buf), sidebar_get_current());
1111 else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1) {
1112 if (menu->menu == MENU_PAGER) {
1113 op = OP_DISPLAY_MESSAGE;
1119 CLEARLINE(main_w, LINES - 1);
1124 if (option (OPTNEWS)) {
1125 unset_option (OPTNEWS);
1126 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1130 mutt_expand_path (buf, sizeof (buf));
1131 if (mx_get_magic (buf) <= 0) {
1132 mutt_error (_("%s is not a mailbox."), buf);
1135 m_strreplace(&CurrentFolder, buf);
1140 if (Context->cinfo && Context->realpath)
1141 m_strreplace(&LastFolder, Context->realpath);
1143 m_strreplace(&LastFolder, Context->path);
1144 oldcount = Context ? Context->msgcount : 0;
1146 if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
1147 if (check == M_NEW_MAIL || check == M_REOPENED)
1148 update_index (menu, Context, check, oldcount, index_hint);
1150 set_option (OPTSEARCHINVALID);
1151 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1159 /* Set CurrentMenu to MENU_MAIN before executing any folder
1160 * hooks so that all the index menu functions are available to
1164 CurrentMenu = MENU_MAIN;
1165 mutt_folder_hook (buf);
1167 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
1168 menu->current = ci_first_message ();
1172 sidebar_set_current (buf);
1174 mutt_clear_error ();
1175 buffy_check (0); /* force the buffy check after we have changed
1177 menu->redraw = REDRAW_FULL;
1178 set_option (OPTSEARCHINVALID);
1181 case OP_DISPLAY_MESSAGE:
1182 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1187 * toggle the weeding of headers so that a user can press the key
1188 * again while reading the message.
1190 if (op == OP_DISPLAY_HEADERS)
1191 toggle_option (OPTWEED);
1193 unset_option (OPTNEEDRESORT);
1195 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
1196 mutt_uncollapse_thread (Context, CURHDR);
1197 mutt_set_virtual (Context);
1198 if (option (OPTUNCOLLAPSEJUMP))
1199 menu->current = mutt_thread_next_unread (Context, CURHDR);
1202 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1203 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1205 if ((op = mutt_display_message (CURHDR)) == -1) {
1206 unset_option (OPTNEEDRESORT);
1210 menu->menu = MENU_PAGER;
1211 menu->oldcurrent = menu->current;
1216 if (menu->menu == MENU_MAIN && attach_msg) {
1221 if ((menu->menu == MENU_MAIN)
1222 && (query_quadoption2(mod_core.quit,
1223 _("Exit Madmutt without saving?")) == M_YES))
1226 mx_fastclose_mailbox (Context);
1237 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1238 /* if we were in the pager, redisplay the message */
1239 if (menu->menu == MENU_PAGER) {
1240 op = OP_DISPLAY_MESSAGE;
1244 menu->redraw = REDRAW_CURRENT;
1247 case OP_MAIN_BREAK_THREAD:
1252 if ((Sort & SORT_MASK) != SORT_THREADS)
1253 mutt_error (_("Threading is not enabled."));
1257 HEADER *oldcur = CURHDR;
1259 mutt_break_thread (CURHDR);
1260 mutt_sort_headers (Context, 1);
1261 menu->current = oldcur->virtual;
1264 Context->changed = 1;
1265 mutt_message _("Thread broken");
1267 if (menu->menu == MENU_PAGER) {
1268 op = OP_DISPLAY_MESSAGE;
1272 menu->redraw |= REDRAW_INDEX;
1276 case OP_MAIN_LINK_THREADS:
1281 if ((Sort & SORT_MASK) != SORT_THREADS)
1282 mutt_error (_("Threading is not enabled."));
1284 else if (!CURHDR->env->message_id)
1285 mutt_error (_("No Message-ID: header available to link thread"));
1287 else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
1288 mutt_error (_("First, please tag a message to be linked here"));
1291 HEADER *oldcur = CURHDR;
1293 if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
1295 mutt_sort_headers (Context, 1);
1296 menu->current = oldcur->virtual;
1298 Context->changed = 1;
1299 mutt_message _("Threads linked");
1302 mutt_error (_("No thread linked"));
1305 if (menu->menu == MENU_PAGER) {
1306 op = OP_DISPLAY_MESSAGE;
1310 menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
1313 case OP_MAIN_NEXT_UNDELETED:
1316 if (menu->current >= Context->vcount - 1) {
1317 if (menu->menu == MENU_MAIN)
1318 mutt_error (_("You are on the last message."));
1322 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1323 menu->current = menu->oldcurrent;
1324 if (menu->menu == MENU_MAIN)
1325 mutt_error (_("No undeleted messages."));
1327 else if (menu->menu == MENU_PAGER) {
1328 op = OP_DISPLAY_MESSAGE;
1332 menu->redraw = REDRAW_MOTION;
1338 if (menu->current >= Context->vcount - 1) {
1339 if (menu->menu == MENU_MAIN)
1340 mutt_error (_("You are on the last message."));
1345 if (menu->menu == MENU_PAGER) {
1346 op = OP_DISPLAY_MESSAGE;
1350 menu->redraw = REDRAW_MOTION;
1353 case OP_MAIN_PREV_UNDELETED:
1356 if (menu->current < 1) {
1357 mutt_error (_("You are on the first message."));
1361 if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
1362 menu->current = menu->oldcurrent;
1363 if (menu->menu == MENU_MAIN)
1364 mutt_error (_("No undeleted messages."));
1366 else if (menu->menu == MENU_PAGER) {
1367 op = OP_DISPLAY_MESSAGE;
1371 menu->redraw = REDRAW_MOTION;
1377 if (menu->current < 1) {
1378 if (menu->menu == MENU_MAIN)
1379 mutt_error (_("You are on the first message."));
1384 if (menu->menu == MENU_PAGER) {
1385 op = OP_DISPLAY_MESSAGE;
1389 menu->redraw = REDRAW_MOTION;
1392 case OP_DECRYPT_COPY:
1393 case OP_DECRYPT_SAVE:
1394 case OP_COPY_MESSAGE:
1396 case OP_DECODE_COPY:
1397 case OP_DECODE_SAVE:
1400 if (mutt_save_message (tag ? NULL : CURHDR,
1401 (op == OP_DECRYPT_SAVE) ||
1402 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1403 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1404 (op == OP_DECRYPT_SAVE)
1405 || (op == OP_DECRYPT_COPY)
1406 || 0, &menu->redraw) == 0 && (op == OP_SAVE
1413 menu->redraw |= REDRAW_INDEX;
1414 else if (option (OPTRESOLVE)) {
1415 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1416 menu->current = menu->oldcurrent;
1417 menu->redraw |= REDRAW_CURRENT;
1420 menu->redraw |= REDRAW_MOTION_RESYNCH;
1423 menu->redraw |= REDRAW_CURRENT;
1427 case OP_MAIN_NEXT_NEW:
1428 case OP_MAIN_NEXT_UNREAD:
1429 case OP_MAIN_PREV_NEW:
1430 case OP_MAIN_PREV_UNREAD:
1431 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1432 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1434 int first_unread = -1;
1442 for (j = 0; j != Context->vcount; j++) {
1443 #define CURHDRi Context->hdrs[Context->v2r[i]]
1444 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
1445 || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
1447 if (i > Context->vcount - 1) {
1448 mutt_message _("Search wrapped to top.");
1456 mutt_message _("Search wrapped to bottom.");
1458 i = Context->vcount - 1;
1462 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
1463 if (UNREAD (CURHDRi) && first_unread == -1)
1465 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1468 else if ((!CURHDRi->deleted && !CURHDRi->read)) {
1469 if (first_unread == -1)
1471 if ((!CURHDRi->old) && first_new == -1)
1475 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1478 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1479 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1480 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1485 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1486 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1487 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1489 menu->current = first_new;
1490 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1491 op == OP_MAIN_NEXT_NEW_THEN_UNREAD
1492 || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1493 && first_unread != -1)
1494 menu->current = first_unread;
1496 if (menu->current == -1) {
1497 menu->current = menu->oldcurrent;
1498 mutt_error ("%s%s.",
1499 (op == OP_MAIN_NEXT_NEW
1501 OP_MAIN_PREV_NEW) ? _("No new messages") :
1502 _("No unread messages"),
1503 Context->pattern ? _(" in this limited view") : "");
1505 else if (menu->menu == MENU_PAGER) {
1506 op = OP_DISPLAY_MESSAGE;
1510 menu->redraw = REDRAW_MOTION;
1513 case OP_FLAG_MESSAGE:
1518 CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
1521 for (j = 0; j < Context->vcount; j++) {
1522 if (Context->hdrs[Context->v2r[j]]->tagged)
1523 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1524 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1527 menu->redraw |= REDRAW_INDEX;
1530 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1531 if (option (OPTRESOLVE)) {
1532 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1533 menu->current = menu->oldcurrent;
1534 menu->redraw = REDRAW_CURRENT;
1537 menu->redraw = REDRAW_MOTION_RESYNCH;
1540 menu->redraw = REDRAW_CURRENT;
1542 menu->redraw |= REDRAW_STATUS;
1550 CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
1553 for (j = 0; j < Context->vcount; j++) {
1554 if (Context->hdrs[Context->v2r[j]]->tagged) {
1555 if (Context->hdrs[Context->v2r[j]]->read ||
1556 Context->hdrs[Context->v2r[j]]->old)
1557 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
1560 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
1564 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1567 if (CURHDR->read || CURHDR->old)
1568 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1570 mutt_set_flag (Context, CURHDR, M_READ, 1);
1572 if (option (OPTRESOLVE)) {
1573 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1574 menu->current = menu->oldcurrent;
1575 menu->redraw = REDRAW_CURRENT;
1578 menu->redraw = REDRAW_MOTION_RESYNCH;
1581 menu->redraw = REDRAW_CURRENT;
1582 menu->redraw |= REDRAW_STATUS;
1586 case OP_TOGGLE_WRITE:
1588 if (mx_toggle_write (Context) == 0)
1589 menu->redraw |= REDRAW_STATUS;
1592 case OP_MAIN_NEXT_THREAD:
1593 case OP_MAIN_NEXT_SUBTHREAD:
1594 case OP_MAIN_PREV_THREAD:
1595 case OP_MAIN_PREV_SUBTHREAD:
1599 case OP_MAIN_NEXT_THREAD:
1600 menu->current = mutt_next_thread (CURHDR);
1603 case OP_MAIN_NEXT_SUBTHREAD:
1604 menu->current = mutt_next_subthread (CURHDR);
1607 case OP_MAIN_PREV_THREAD:
1608 menu->current = mutt_previous_thread (CURHDR);
1611 case OP_MAIN_PREV_SUBTHREAD:
1612 menu->current = mutt_previous_subthread (CURHDR);
1616 if (menu->current < 0) {
1617 menu->current = menu->oldcurrent;
1618 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1619 mutt_error (_("No more threads."));
1622 mutt_error (_("You are on the first thread."));
1624 else if (menu->menu == MENU_PAGER) {
1625 op = OP_DISPLAY_MESSAGE;
1629 menu->redraw = REDRAW_MOTION;
1632 case OP_MAIN_PARENT_MESSAGE:
1636 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
1637 menu->current = menu->oldcurrent;
1639 else if (menu->menu == MENU_PAGER) {
1640 op = OP_DISPLAY_MESSAGE;
1644 menu->redraw = REDRAW_MOTION;
1647 case OP_MAIN_SET_FLAG:
1648 case OP_MAIN_CLEAR_FLAG:
1653 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0) {
1654 menu->redraw = REDRAW_STATUS;
1656 menu->redraw |= REDRAW_INDEX;
1657 else if (option (OPTRESOLVE)) {
1658 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1659 menu->current = menu->oldcurrent;
1660 menu->redraw |= REDRAW_CURRENT;
1663 menu->redraw |= REDRAW_MOTION_RESYNCH;
1666 menu->redraw |= REDRAW_CURRENT;
1670 case OP_MAIN_COLLAPSE_THREAD:
1674 if ((Sort & SORT_MASK) != SORT_THREADS) {
1675 mutt_error (_("Threading is not enabled."));
1680 if (CURHDR->collapsed) {
1681 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1682 mutt_set_virtual (Context);
1683 if (option (OPTUNCOLLAPSEJUMP))
1684 menu->current = mutt_thread_next_unread (Context, CURHDR);
1686 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR)) {
1687 menu->current = mutt_collapse_thread (Context, CURHDR);
1688 mutt_set_virtual (Context);
1691 mutt_error (_("Thread contains unread messages."));
1696 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1700 case OP_MAIN_COLLAPSE_ALL:
1704 if ((Sort & SORT_MASK) != SORT_THREADS) {
1705 mutt_error (_("Threading is not enabled."));
1712 THREAD *thread, *top;
1715 if (CURHDR->collapsed)
1716 final = mutt_uncollapse_thread (Context, CURHDR);
1717 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1718 final = mutt_collapse_thread (Context, CURHDR);
1720 final = CURHDR->virtual;
1722 base = Context->hdrs[Context->v2r[final]];
1724 top = Context->tree;
1725 Context->collapsed = !Context->collapsed;
1726 while ((thread = top) != NULL) {
1727 while (!thread->message)
1728 thread = thread->child;
1729 h = thread->message;
1731 if (h->collapsed != Context->collapsed) {
1733 mutt_uncollapse_thread (Context, h);
1734 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1735 mutt_collapse_thread (Context, h);
1740 mutt_set_virtual (Context);
1741 for (j = 0; j < Context->vcount; j++) {
1742 if (Context->hdrs[Context->v2r[j]]->index == base->index) {
1748 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1752 /* --------------------------------------------------------------------
1753 * These functions are invoked directly from the internal-pager
1756 case OP_BOUNCE_MESSAGE:
1760 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1763 case OP_CREATE_ALIAS:
1764 mutt_create_alias (Context
1765 && Context->vcount ? CURHDR->env : NULL, NULL);
1766 MAYBE_REDRAW (menu->redraw);
1767 menu->redraw |= REDRAW_CURRENT;
1772 mutt_query_menu (NULL, 0);
1773 MAYBE_REDRAW (menu->redraw);
1776 case OP_PURGE_MESSAGE:
1782 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1785 mutt_tag_set_flag (M_DELETE, 1);
1786 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1787 if (option (OPTDELETEUNTAG))
1788 mutt_tag_set_flag (M_TAG, 0);
1789 menu->redraw = REDRAW_INDEX;
1792 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1793 mutt_set_flag (Context, CURHDR, M_PURGED,
1794 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1795 if (option (OPTDELETEUNTAG))
1796 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1797 if (option (OPTRESOLVE)) {
1798 if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
1799 menu->current = menu->oldcurrent;
1800 menu->redraw = REDRAW_CURRENT;
1802 else if (menu->menu == MENU_PAGER) {
1803 op = OP_DISPLAY_MESSAGE;
1807 menu->redraw |= REDRAW_MOTION_RESYNCH;
1810 menu->redraw = REDRAW_CURRENT;
1812 menu->redraw |= REDRAW_STATUS;
1815 case OP_DELETE_THREAD:
1816 case OP_DELETE_SUBTHREAD:
1821 CHECK_MX_ACL (Context, ACL_DELETE, _("Deletion"));
1823 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1824 op == OP_DELETE_THREAD ? 0 : 1);
1827 if (option (OPTDELETEUNTAG))
1828 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1829 op == OP_DELETE_THREAD ? 0 : 1);
1830 if (option (OPTRESOLVE))
1831 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1832 menu->current = menu->oldcurrent;
1833 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1839 if (Context && Context->magic == M_NNTP) {
1840 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1841 ((nntp_data_t *) Context->data)->group))
1842 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1847 case OP_DISPLAY_ADDRESS:
1850 mutt_display_address (CURHDR->env);
1853 case OP_ENTER_COMMAND:
1854 CurrentMenu = MENU_MAIN;
1855 mutt_enter_command ();
1856 mutt_check_rescore (Context);
1857 if (option (OPTFORCEREDRAWINDEX))
1858 menu->redraw = REDRAW_FULL;
1859 unset_option (OPTFORCEREDRAWINDEX);
1860 unset_option (OPTFORCEREDRAWPAGER);
1863 case OP_EDIT_MESSAGE:
1869 CHECK_MX_ACL (Context, ACL_INSERT, _("Editing"));
1871 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1872 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1873 mutt_edit_message (Context, tag ? NULL : CURHDR);
1874 menu->redraw = REDRAW_FULL;
1878 case OP_FORWARD_MESSAGE:
1883 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1884 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1885 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
1886 menu->redraw = REDRAW_FULL;
1889 case OP_GROUP_REPLY:
1894 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1895 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1897 ci_send_message (SENDREPLY | SENDGROUPREPLY, NULL, NULL, Context,
1898 tag ? NULL : CURHDR);
1899 menu->redraw = REDRAW_FULL;
1907 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1908 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1910 ci_send_message (SENDREPLY | SENDLISTREPLY, NULL, NULL, Context,
1911 tag ? NULL : CURHDR);
1912 menu->redraw = REDRAW_FULL;
1917 ci_send_message (0, NULL, NULL, Context, NULL);
1918 menu->redraw = REDRAW_FULL;
1921 case OP_EXTRACT_KEYS:
1924 crypt_extract_keys_from_messages (tag ? NULL : CURHDR);
1925 menu->redraw = REDRAW_FULL;
1929 case OP_CHECK_TRADITIONAL:
1932 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
1933 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
1935 if (menu->menu == MENU_PAGER) {
1936 op = OP_DISPLAY_MESSAGE;
1944 mutt_pipe_message (tag ? NULL : CURHDR);
1945 MAYBE_REDRAW (menu->redraw);
1951 mutt_print_message (tag ? NULL : CURHDR);
1954 case OP_MAIN_READ_THREAD:
1955 case OP_MAIN_READ_SUBTHREAD:
1960 CHECK_MX_ACL (Context, ACL_SEEN, _("Marking as read"));
1962 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
1963 op == OP_MAIN_READ_THREAD ? 0 : 1);
1966 if (option (OPTRESOLVE)) {
1967 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
1968 mutt_next_thread (CURHDR) :
1969 mutt_next_subthread (CURHDR))) == -1)
1970 menu->current = menu->oldcurrent;
1972 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1976 case OP_RECALL_MESSAGE:
1978 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
1979 menu->redraw = REDRAW_FULL;
1988 for (j = 0; j < Context->vcount; j++) {
1989 if (Context->hdrs[Context->v2r[j]]->tagged)
1990 mutt_resend_message (NULL, Context,
1991 Context->hdrs[Context->v2r[j]]);
1995 mutt_resend_message (NULL, Context, CURHDR);
1997 menu->redraw = REDRAW_FULL;
2003 case OP_FORWARD_TO_GROUP:
2005 if ((op == OP_FOLLOWUP || op == OP_FORWARD_TO_GROUP) &&
2006 Context && Context->msgcount == 0) {
2007 mutt_error (_("There are no messages."));
2010 else if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2011 m_strcasecmp(CURHDR->env->followup_to, "poster") ||
2012 query_quadoption (OPT_FOLLOWUPTOPOSTER,
2013 _("Reply by mail as poster prefers?")) !=
2015 if (Context && Context->magic == M_NNTP
2016 && !((nntp_data_t *) Context->data)->allowed
2017 && query_quadoption (OPT_TOMODERATED,
2019 ("Posting to this group not allowed, may be moderated. Continue?"))
2023 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2026 if (op == OP_FOLLOWUP)
2027 ci_send_message (SENDNEWS | SENDREPLY, NULL, NULL, Context,
2028 tag ? NULL : CURHDR);
2030 ci_send_message (SENDNEWS | SENDFORWARD, NULL, NULL, Context,
2031 tag ? NULL : CURHDR);
2033 menu->redraw = REDRAW_FULL;
2043 if (tag || !(CURHDR->security & PGP_TRADITIONAL_CHECKED))
2044 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2046 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2047 menu->redraw = REDRAW_FULL;
2050 case OP_SHELL_ESCAPE:
2051 mutt_shell_escape ();
2052 MAYBE_REDRAW (menu->redraw);
2056 case OP_TAG_SUBTHREAD:
2059 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2060 op == OP_TAG_THREAD ? 0 : 1);
2063 if (option (OPTRESOLVE)) {
2064 menu->current = mutt_next_thread (CURHDR);
2066 if (menu->current == -1)
2067 menu->current = menu->oldcurrent;
2069 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2078 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2081 mutt_tag_set_flag (M_DELETE, 0);
2082 mutt_tag_set_flag (M_PURGED, 0);
2083 menu->redraw = REDRAW_INDEX;
2086 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2087 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2088 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1) {
2090 menu->redraw = REDRAW_MOTION_RESYNCH;
2093 menu->redraw = REDRAW_CURRENT;
2095 menu->redraw |= REDRAW_STATUS;
2098 case OP_UNDELETE_THREAD:
2099 case OP_UNDELETE_SUBTHREAD:
2104 CHECK_MX_ACL (Context, ACL_DELETE, _("Undeletion"));
2106 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2107 op == OP_UNDELETE_THREAD ? 0 : 1)
2108 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2109 op == OP_UNDELETE_THREAD ? 0 : 1);
2112 if (option (OPTRESOLVE)) {
2113 if (op == OP_UNDELETE_THREAD)
2114 menu->current = mutt_next_thread (CURHDR);
2116 menu->current = mutt_next_subthread (CURHDR);
2118 if (menu->current == -1)
2119 menu->current = menu->oldcurrent;
2121 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2130 if (option (OPTFORCEBUFFYCHECK))
2133 menu->redraw = REDRAW_FULL;
2136 case OP_VIEW_ATTACHMENTS:
2139 mutt_view_attachments (CURHDR);
2140 if (CURHDR->attach_del)
2141 Context->changed = 1;
2142 menu->redraw = REDRAW_FULL;
2152 case OP_SIDEBAR_SCROLL_UP:
2153 case OP_SIDEBAR_SCROLL_DOWN:
2154 case OP_SIDEBAR_NEXT:
2155 case OP_SIDEBAR_PREV:
2156 case OP_SIDEBAR_NEXT_NEW:
2157 case OP_SIDEBAR_PREV_NEW:
2158 sidebar_scroll (op);
2162 if (menu->menu == MENU_MAIN)
2163 km_error_key (MENU_MAIN);
2166 if (menu->menu == MENU_PAGER) {
2167 menu->menu = MENU_MAIN;
2168 menu->redraw = REDRAW_FULL;
2176 /* Close all open IMAP connections */
2179 /* Close all open NNTP connections */
2184 mutt_menuDestroy (&menu);
2188 void mutt_set_header_color (CONTEXT * ctx, HEADER * curhdr)
2195 for (color = ColorIndexList; color; color = color->next)
2196 if (mutt_pattern_exec
2197 (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr)) {
2198 curhdr->pair = color->pair;
2201 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];