2 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
20 #include "mutt_curses.h"
22 #include "mutt_menu.h"
35 #include "imap_private.h"
38 #include "mutt_crypt.h"
53 static const char *No_mailbox_is_open = N_("No mailbox is open.");
54 static const char *There_are_no_messages = N_("There are no messages.");
55 static const char *Mailbox_is_read_only = N_("Mailbox is read-only.");
56 static const char *Function_not_permitted_in_attach_message_mode = N_("Function not permitted in attach-message mode.");
57 static const char *No_visible = N_("No visible messages.");
59 #define CHECK_MSGCOUNT if (!Context) \
62 mutt_error _(No_mailbox_is_open); \
65 else if (!Context->msgcount) \
68 mutt_error _(There_are_no_messages); \
72 #define CHECK_VISIBLE if (Context && menu->current >= Context->vcount) \
75 mutt_error _(No_visible); \
80 #define CHECK_READONLY if (Context->readonly) \
83 mutt_error _(Mailbox_is_read_only); \
88 /* the error message returned here could be better. */
89 #define CHECK_IMAP_ACL(aclbit) if (Context->magic == M_IMAP) \
90 if (mutt_bit_isset (((IMAP_DATA *)Context->data)->capabilities, ACL) \
91 && !mutt_bit_isset(((IMAP_DATA *)Context->data)->rights,aclbit)){ \
93 mutt_error ("Operation not permitted by the IMAP ACL for this mailbox"); \
98 #define CHECK_ATTACH if(option(OPTATTACHMSG)) \
101 mutt_error _(Function_not_permitted_in_attach_message_mode); \
105 #define CURHDR Context->hdrs[Context->v2r[menu->current]]
106 #define OLDHDR Context->hdrs[Context->v2r[menu->oldcurrent]]
107 #define UNREAD(h) mutt_thread_contains_unread (Context, h)
109 extern const char *ReleaseDate;
110 extern size_t UngetCount;
112 void index_make_entry (char *s, size_t l, MUTTMENU *menu, int num)
114 format_flag flag = M_FORMAT_MAKEPRINT | M_FORMAT_ARROWCURSOR | M_FORMAT_INDEX;
115 int edgemsgno, reverse = Sort & SORT_REVERSE;
116 HEADER *h = Context->hdrs[Context->v2r[num]];
119 if ((Sort & SORT_MASK) == SORT_THREADS && h->tree)
121 flag |= M_FORMAT_TREE; /* display the thread tree */
122 if (h->display_subject)
123 flag |= M_FORMAT_FORCESUBJ;
128 if (menu->top + menu->pagelen > menu->max)
129 edgemsgno = Context->v2r[menu->max - 1];
131 edgemsgno = Context->v2r[menu->top + menu->pagelen - 1];
134 edgemsgno = Context->v2r[menu->top];
136 for (tmp = h->thread->parent; tmp; tmp = tmp->parent)
141 /* if no ancestor is visible on current screen, provisionally force
143 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno < edgemsgno)
145 flag |= M_FORMAT_FORCESUBJ;
148 else if (tmp->message->virtual >= 0)
151 if (flag & M_FORMAT_FORCESUBJ)
153 for (tmp = h->thread->prev; tmp; tmp = tmp->prev)
158 /* ...but if a previous sibling is available, don't force it */
159 if (reverse ? tmp->message->msgno > edgemsgno : tmp->message->msgno < edgemsgno)
161 else if (tmp->message->virtual >= 0)
163 flag &= ~M_FORMAT_FORCESUBJ;
171 _mutt_make_string (s, l, NONULL (HdrFmt), Context, h, flag);
174 int index_color (int index_no)
176 HEADER *h = Context->hdrs[Context->v2r[index_no]];
181 mutt_set_header_color (Context, h);
185 static int ci_next_undeleted (int msgno)
189 for (i=msgno+1; i < Context->vcount; i++)
190 if (! Context->hdrs[Context->v2r[i]]->deleted)
195 static int ci_previous_undeleted (int msgno)
199 for (i=msgno-1; i>=0; i--)
200 if (! Context->hdrs[Context->v2r[i]]->deleted)
205 /* Return the index of the first new message, or failing that, the first
208 static int ci_first_message (void)
212 if (Context && Context->msgcount)
214 for (i=0; i < Context->vcount; i++)
216 if (! Context->hdrs[Context->v2r[i]]->read &&
217 ! Context->hdrs[Context->v2r[i]]->deleted)
219 if (! Context->hdrs[Context->v2r[i]]->old)
228 /* If Sort is reverse and not threaded, the latest message is first.
229 * If Sort is threaded, the latest message is first iff exactly one
230 * of Sort and SortAux are reverse.
232 if (((Sort & SORT_REVERSE) && (Sort & SORT_MASK) != SORT_THREADS) ||
233 ((Sort & SORT_MASK) == SORT_THREADS &&
234 ((Sort ^ SortAux) & SORT_REVERSE)))
237 return (Context->vcount ? Context->vcount - 1 : 0);
242 /* This should be in mx.c, but it only gets used here. */
243 static int mx_toggle_write (CONTEXT *ctx)
250 mutt_error _("Cannot toggle write on a readonly mailbox!");
257 mutt_message _("Changes to folder will be written on folder exit.");
262 mutt_message _("Changes to folder will not be written.");
268 static void update_index (MUTTMENU *menu, CONTEXT *ctx, int check,
269 int oldcount, int index_hint)
271 /* store pointers to the newly added messages */
272 HEADER **save_new = NULL;
275 /* take note of the current message */
278 if (menu->current < Context->vcount)
279 menu->oldcurrent = index_hint;
281 oldcount = 0; /* invalid message number! */
284 /* We are in a limited view. Check if the new message(s) satisfy
285 * the limit criteria. If they do, set their virtual msgno so that
286 * they will be visible in the limited view */
287 if (Context->pattern)
289 #define THIS_BODY Context->hdrs[j]->content
290 if (oldcount || check == M_REOPENED)
292 for (j = (check == M_REOPENED) ? 0 : oldcount; j < Context->msgcount; j++)
294 if (mutt_pattern_exec (Context->limit_pattern,
295 M_MATCH_FULL_ADDRESS,
296 Context, Context->hdrs[j]))
298 Context->hdrs[j]->virtual = Context->vcount;
299 Context->v2r[Context->vcount] = j;
300 Context->hdrs[j]->limited = 1;
302 Context->vsize += THIS_BODY->length + THIS_BODY->offset - THIS_BODY->hdr_offset;
309 /* save the list of new messages */
310 if (oldcount && check != M_REOPENED
311 && ((Sort & SORT_MASK) == SORT_THREADS))
313 save_new = (HEADER **) safe_malloc (sizeof (HEADER *) * (Context->msgcount - oldcount));
314 for (j = oldcount; j < Context->msgcount; j++)
315 save_new[j-oldcount] = Context->hdrs[j];
318 /* if the mailbox was reopened, need to rethread from scratch */
319 mutt_sort_headers (Context, (check == M_REOPENED));
321 /* uncollapse threads with new mail */
322 if ((Sort & SORT_MASK) == SORT_THREADS)
324 if (check == M_REOPENED)
328 Context->collapsed = 0;
330 for (h = Context->tree; h; h = h->next)
332 for (j = h; !j->message; j = j->child)
334 mutt_uncollapse_thread (Context, j->message);
336 mutt_set_virtual (Context);
340 for (j = 0; j < Context->msgcount - oldcount; j++)
344 for (k = 0; k < Context->msgcount; k++)
346 HEADER *h = Context->hdrs[k];
347 if (h == save_new[j] && (!Context->pattern || h->limited))
348 mutt_uncollapse_thread (Context, h);
352 mutt_set_virtual (Context);
359 /* restore the current message to the message it was pointing to */
360 for (j = 0; j < Context->vcount; j++)
362 if (Context->hdrs[Context->v2r[j]]->index == menu->oldcurrent)
370 if (menu->current < 0)
371 menu->current = ci_first_message ();
375 static void resort_index (MUTTMENU *menu)
378 HEADER *current = CURHDR;
381 mutt_sort_headers (Context, 0);
382 /* Restore the current message */
384 for (i = 0; i < Context->vcount; i++)
386 if (Context->hdrs[Context->v2r[i]] == current)
393 if ((Sort & SORT_MASK) == SORT_THREADS && menu->current < 0)
394 menu->current = mutt_parent_message (Context, current);
396 if (menu->current < 0)
397 menu->current = ci_first_message ();
399 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
402 struct mapping_t IndexHelp[] = {
403 { N_("Quit"), OP_QUIT },
404 { N_("Del"), OP_DELETE },
405 { N_("Undel"), OP_UNDELETE },
406 { N_("Save"), OP_SAVE },
407 { N_("Mail"), OP_MAIL },
408 { N_("Reply"), OP_REPLY },
409 { N_("Group"), OP_GROUP_REPLY },
410 { N_("Help"), OP_HELP },
415 struct mapping_t IndexNewsHelp[] = {
416 { N_("Quit"), OP_QUIT },
417 { N_("Del"), OP_DELETE },
418 { N_("Undel"), OP_UNDELETE },
419 { N_("Save"), OP_SAVE },
420 { N_("Post"), OP_POST },
421 { N_("Followup"), OP_FOLLOWUP },
422 { N_("Catchup"), OP_CATCHUP },
423 { N_("Help"), OP_HELP },
428 /* This function handles the message index window as well as commands returned
429 * from the pager (MENU_PAGER).
431 int mutt_index_menu (void)
433 char buf[LONG_STRING], helpstr[SHORT_STRING];
436 int done = 0; /* controls when to exit the "event" loop */
438 int tag = 0; /* has the tag-prefix command been pressed? */
443 char *cp; /* temporary variable. */
444 int index_hint; /* used to restore cursor position */
445 int do_buffy_notify = 1;
446 int close = 0; /* did we OP_QUIT or OP_EXIT out of this menu? */
447 int attach_msg = option(OPTATTACHMSG);
449 menu = mutt_new_menu ();
450 menu->menu = MENU_MAIN;
452 menu->pagelen = LINES - 3;
453 menu->make_entry = index_make_entry;
454 menu->color = index_color;
455 menu->current = ci_first_message ();
456 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
458 (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp :
463 mutt_buffy_check(1); /* force the buffy check after we enter the folder */
467 tag = 0; /* clear the tag-prefix */
469 menu->max = Context ? Context->vcount : 0;
470 oldcount = Context ? Context->msgcount : 0;
472 /* check if we need to resort the index because just about
473 * any 'op' below could do mutt_enter_command(), either here or
474 * from any new menu launched, and change $sort/$sort_aux
476 if (option (OPTNEEDRESORT) && Context && Context->msgcount)
479 if (option (OPTREDRAWTREE) && Context && Context->msgcount && (Sort & SORT_MASK) == SORT_THREADS)
481 mutt_draw_tree (Context);
482 menu->redraw |= REDRAW_STATUS;
483 unset_option (OPTREDRAWTREE);
486 if (Context && !attach_msg)
489 /* check for new mail in the mailbox. If nonzero, then something has
490 * changed about the file (either we got new mail or the file was
491 * modified underneath us.)
495 imap_allow_reopen (Context);
498 index_hint = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ? CURHDR->index : 0;
500 if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0)
504 /* fatal error occurred */
506 menu->redraw = REDRAW_FULL;
509 set_option (OPTSEARCHINVALID);
511 else if (check == M_NEW_MAIL || check == M_REOPENED || check == M_FLAGS)
513 update_index (menu, Context, check, oldcount, index_hint);
515 /* notify the user of new mail */
516 if (check == M_REOPENED)
517 mutt_error _("Mailbox was externally modified. Flags may be wrong.");
518 else if (check == M_NEW_MAIL)
520 mutt_message _("New mail in this mailbox.");
521 if (option (OPTBEEPNEW))
523 } else if (check == M_FLAGS)
524 mutt_message _("Mailbox was externally modified.");
526 /* avoid the message being overwritten by buffy */
529 menu->redraw = REDRAW_FULL;
530 menu->max = Context->vcount;
532 set_option (OPTSEARCHINVALID);
538 imap_disallow_reopen (Context);
543 /* check for new mail in the incoming folders */
545 if ((newcount = mutt_buffy_check (0)) != oldcount)
546 menu->redraw |= REDRAW_STATUS;
549 if (mutt_buffy_notify () && option (OPTBEEPNEW))
559 if (menu->redraw & REDRAW_FULL)
561 menu_redraw_full (menu);
562 draw_sidebar(menu->menu);
566 if (menu->menu == MENU_MAIN)
568 if (Context && Context->hdrs && !(menu->current >= Context->vcount))
570 menu_check_recenter (menu);
572 if (menu->redraw & REDRAW_INDEX)
574 menu_redraw_index (menu);
575 menu->redraw |= REDRAW_STATUS;
577 else if (menu->redraw & (REDRAW_MOTION_RESYNCH | REDRAW_MOTION))
578 menu_redraw_motion (menu);
579 else if (menu->redraw & REDRAW_CURRENT)
580 menu_redraw_current (menu);
583 if (menu->redraw & REDRAW_STATUS)
586 menu_status_line (buf, sizeof (buf), menu, NONULL (Status));
588 CLEARLINE (option (OPTSTATUSONTOP) ? 0 : LINES-2);
589 SETCOLOR (MT_COLOR_STATUS);
590 mutt_paddstr (COLS, buf);
591 SETCOLOR (MT_COLOR_NORMAL);
592 menu->redraw &= ~REDRAW_STATUS;
596 if (menu->current < menu->max)
597 menu->oldcurrent = menu->current;
599 menu->oldcurrent = -1;
601 if (option (OPTARROWCURSOR))
602 move (menu->current - menu->top + menu->offset, 2);
604 move (menu->current - menu->top + menu->offset, COLS - 1);
607 op = km_dokey (MENU_MAIN);
609 dprint(4, (debugfile, "mutt_index_menu[%d]: Got op %d\n", __LINE__, op));
611 #if defined (USE_SLANG_CURSES) || defined (HAVE_RESIZETERM)
615 mutt_resize_screen ();
616 menu->redraw = REDRAW_FULL;
617 menu->menu = MENU_MAIN;
619 menu->top = 0; /* so we scroll the right amount */
621 * force a real complete redraw. clrtobot() doesn't seem to be able
622 * to handle every case without this.
624 clearok(stdscr,TRUE);
630 continue; /* either user abort or timeout */
634 /* special handling for the tag-prefix function */
635 if (op == OP_TAG_PREFIX)
639 mutt_error _("No mailbox is open.");
643 if (!Context->tagged)
645 mutt_error _("No tagged messages.");
650 /* give visual indication that the next command is a tag- command */
651 mvaddstr (LINES - 1, 0, "tag-");
654 /* get the real command */
655 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX)
657 /* abort tag sequence */
662 else if (option (OPTAUTOTAG) && Context && Context->tagged)
665 if (op == OP_TAG_PREFIX_COND)
669 mutt_error _("No mailbox is open.");
673 if (!Context->tagged)
679 if(tmp.op==OP_END_COND)break;
681 mutt_message _("Nothing to do.");
686 /* give visual indication that the next command is a tag- command */
687 mvaddstr (LINES - 1, 0, "tag-");
690 /* get the real command */
691 if ((op = km_dokey (MENU_MAIN)) == OP_TAG_PREFIX)
693 /* abort tag sequence */
703 if (menu->current < menu->max)
704 menu->oldcurrent = menu->current;
706 menu->oldcurrent = -1;
708 mutt_curs_set (1); /* fallback from the pager */
712 unset_option (OPTNEWS); /* for any case */
718 /* ----------------------------------------------------------------------
723 menu_bottom_page (menu);
726 menu_first_entry (menu);
729 menu_middle_page (menu);
735 menu_half_down (menu);
738 menu_next_line (menu);
741 menu_prev_line (menu);
744 menu_next_page (menu);
747 menu_prev_page (menu);
750 menu_last_entry (menu);
753 menu_top_page (menu);
756 menu_current_top (menu);
758 case OP_CURRENT_MIDDLE:
759 menu_current_middle (menu);
761 case OP_CURRENT_BOTTOM:
762 menu_current_bottom (menu);
769 if (Context->magic == M_NNTP)
773 if (op == OP_GET_MESSAGE)
776 if (mutt_get_field (_("Enter Message-Id: "), buf, sizeof (buf), 0) != 0
782 LIST *ref = CURHDR->env->references;
785 mutt_error _("Article has no parent reference!");
788 strfcpy (buf, ref->data, sizeof (buf));
790 if (!Context->id_hash)
791 Context->id_hash = mutt_make_id_hash (Context);
792 if ((h = hash_find (Context->id_hash, buf)))
794 if (h->virtual != -1)
796 menu->current = h->virtual;
797 menu->redraw = REDRAW_MOTION_RESYNCH;
799 else if (h->collapsed)
801 mutt_uncollapse_thread (Context, h);
802 mutt_set_virtual (Context);
803 menu->current = h->virtual;
804 menu->redraw = REDRAW_MOTION_RESYNCH;
807 mutt_error _("Message not visible in limited view.");
811 if (nntp_check_msgid (Context, buf) == 0)
813 h = Context->hdrs[Context->msgcount-1];
814 mutt_sort_headers (Context, 0);
815 menu->current = h->virtual;
816 menu->redraw = REDRAW_FULL;
819 mutt_error (_("Article %s not found on server"), buf);
824 case OP_GET_CHILDREN:
825 case OP_RECONSTRUCT_THREAD:
827 if (Context->magic == M_NNTP)
830 int old = CURHDR->index, i;
832 if (!CURHDR->env->message_id)
834 mutt_error _("No Message-Id. Unable to perform operation");
838 if (!Context->id_hash)
839 Context->id_hash = mutt_make_id_hash (Context);
840 strfcpy (buf, CURHDR->env->message_id, sizeof (buf));
842 if (op == OP_RECONSTRUCT_THREAD)
844 LIST *ref = CURHDR->env->references;
847 nntp_check_msgid (Context, ref->data);
848 /* the last msgid in References is the root message */
850 strfcpy (buf, ref->data, sizeof (buf));
854 mutt_message _("Check for children of message...");
855 if (nntp_check_children (Context, buf) == 0)
857 mutt_sort_headers (Context, (op == OP_RECONSTRUCT_THREAD));
858 h = hash_find (Context->id_hash, buf);
859 /* if the root message was retrieved, move to it */
861 menu->current = h->virtual;
862 else /* try to restore old position */
863 for (i = 0; i < Context->msgcount; i++)
864 if (Context->hdrs[i]->index == old)
866 menu->current = Context->hdrs[i]->virtual;
867 /* As an added courtesy, recenter the menu
868 * with the current entry at the middle of the screen */
869 menu_check_recenter (menu);
870 menu_current_middle (menu);
873 menu->redraw = REDRAW_FULL;
883 if (isdigit (LastKey)) mutt_ungetch (LastKey, 0);
885 if (mutt_get_field (_("Jump to message: "), buf, sizeof (buf), 0) != 0
889 if (! isdigit ((unsigned char) buf[0]))
891 mutt_error _("Argument must be a message number.");
896 if (i > 0 && i <= Context->msgcount)
898 for (j = i-1; j < Context->msgcount; j++)
900 if (Context->hdrs[j]->virtual != -1)
903 if (j >= Context->msgcount)
905 for (j = i-2; j >= 0; j--)
907 if (Context->hdrs[j]->virtual != -1)
914 menu->current = Context->hdrs[j]->virtual;
915 if (menu->menu == MENU_PAGER)
917 op = OP_DISPLAY_MESSAGE;
921 menu->redraw = REDRAW_MOTION;
924 mutt_error _("That message is not visible.");
927 mutt_error _("Invalid message number.");
931 /* --------------------------------------------------------------------
932 * `index' specific commands
935 case OP_MAIN_DELETE_PATTERN:
942 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
946 mutt_pattern_func (M_DELETE, _("Delete messages matching: "));
947 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
951 case OP_MAIN_FETCH_MAIL:
955 menu->redraw = REDRAW_FULL;
961 mutt_help (MENU_MAIN);
962 menu->redraw = REDRAW_FULL;
965 case OP_MAIN_SHOW_LIMIT:
967 if (!Context->pattern)
968 mutt_message _("No limit pattern is in effect.");
972 /* i18n: ask for a limit to apply */
973 snprintf (buf, sizeof(buf), _("Limit: %s"),Context->pattern);
974 mutt_message ("%s", buf);
982 menu->oldcurrent = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ?
984 if (op == OP_TOGGLE_READ)
986 char buf[LONG_STRING];
988 if (!Context->pattern || strncmp (Context->pattern, "!~R!~D~s", 8) != 0)
990 snprintf (buf, sizeof (buf), "!~R!~D~s%s",
991 Context->pattern ? Context->pattern : ".*");
992 set_option (OPTHIDEREAD);
996 strfcpy (buf, Context->pattern + 8, sizeof(buf));
997 if (!*buf || strncmp (buf, ".*", 2) == 0)
998 snprintf (buf, sizeof(buf), "~A");
999 unset_option (OPTHIDEREAD);
1001 FREE (&Context->pattern);
1002 Context->pattern = safe_strdup (buf);
1004 if ((op == OP_TOGGLE_READ && mutt_pattern_func (M_LIMIT, NULL) == 0) ||
1005 mutt_pattern_func (M_LIMIT, _("Limit to messages matching: ")) == 0)
1007 if (menu->oldcurrent >= 0)
1009 /* try to find what used to be the current message */
1011 for (i = 0; i < Context->vcount; i++)
1012 if (Context->hdrs[Context->v2r[i]]->index == menu->oldcurrent)
1017 if (menu->current < 0) menu->current = 0;
1021 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1022 if ((Sort & SORT_MASK) == SORT_THREADS)
1023 mutt_draw_tree (Context);
1024 menu->redraw = REDRAW_FULL;
1037 if (query_quadoption (OPT_QUIT, _("Quit Mutt?")) == M_YES)
1041 oldcount = Context ? Context->msgcount : 0;
1043 if (!Context || (check = mx_close_mailbox (Context, &index_hint)) == 0)
1047 if (check == M_NEW_MAIL || check == M_REOPENED)
1048 update_index (menu, Context, check, oldcount, index_hint);
1050 menu->redraw = REDRAW_FULL; /* new mail arrived? */
1051 set_option (OPTSEARCHINVALID);
1058 clearok (stdscr, TRUE);
1059 menu->redraw = REDRAW_FULL;
1063 case OP_SEARCH_REVERSE:
1064 case OP_SEARCH_NEXT:
1065 case OP_SEARCH_OPPOSITE:
1069 if ((menu->current = mutt_search_command (menu->current, op)) == -1)
1070 menu->current = menu->oldcurrent;
1072 menu->redraw = REDRAW_MOTION;
1076 case OP_SORT_REVERSE:
1078 if (mutt_select_sort ((op == OP_SORT_REVERSE)) == 0)
1080 if (Context && Context->msgcount)
1082 resort_index (menu);
1083 set_option (OPTSEARCHINVALID);
1092 if (tag && !option (OPTAUTOTAG))
1094 for (j = 0; j < Context->vcount; j++)
1095 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_TAG, 0);
1096 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1100 mutt_set_flag (Context, CURHDR, M_TAG, !CURHDR->tagged);
1101 menu->redraw = REDRAW_STATUS;
1102 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1)
1105 menu->redraw |= REDRAW_MOTION_RESYNCH;
1108 menu->redraw |= REDRAW_CURRENT;
1112 case OP_MAIN_TAG_PATTERN:
1116 mutt_pattern_func (M_TAG, _("Tag messages matching: "));
1117 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1120 case OP_MAIN_UNDELETE_PATTERN:
1127 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
1130 if (mutt_pattern_func (M_UNDELETE, _("Undelete messages matching: ")) == 0)
1131 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1134 case OP_MAIN_UNTAG_PATTERN:
1138 if (mutt_pattern_func (M_UNTAG, _("Untag messages matching: ")) == 0)
1139 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1142 /* --------------------------------------------------------------------
1143 * The following operations can be performed inside of the pager.
1147 case OP_MAIN_IMAP_FETCH:
1148 if (Context->magic == M_IMAP)
1149 imap_check_mailbox (Context, &index_hint, 1);
1153 case OP_MAIN_SYNC_FOLDER:
1159 int oldvcount = Context->vcount;
1160 int oldcount = Context->msgcount;
1164 /* calculate the number of messages _above_ the cursor,
1165 * so we can keep the cursor on the current message
1167 for (j = 0; j <= menu->current; j++)
1169 if (Context->hdrs[Context->v2r[j]]->deleted)
1173 if ((check = mx_sync_mailbox (Context, &index_hint)) == 0)
1175 if (Context->vcount != oldvcount)
1176 menu->current -= dcount;
1177 set_option (OPTSEARCHINVALID);
1179 else if (check == M_NEW_MAIL || check == M_REOPENED)
1180 update_index (menu, Context, check, oldcount, index_hint);
1183 * do a sanity check even if mx_sync_mailbox failed.
1186 if (menu->current < 0 || menu->current >= Context->vcount)
1187 menu->current = ci_first_message ();
1190 /* check for a fatal error, or all messages deleted */
1194 /* if we were in the pager, redisplay the message */
1195 if (menu->menu == MENU_PAGER)
1197 op = OP_DISPLAY_MESSAGE;
1201 menu->redraw = REDRAW_FULL;
1204 case OP_SIDEBAR_OPEN:
1205 case OP_MAIN_CHANGE_FOLDER:
1206 case OP_MAIN_CHANGE_FOLDER_READONLY:
1208 case OP_MAIN_CHANGE_GROUP:
1209 case OP_MAIN_CHANGE_GROUP_READONLY:
1211 if (attach_msg || option (OPTREADONLY) ||
1213 op == OP_MAIN_CHANGE_GROUP_READONLY ||
1215 op == OP_MAIN_CHANGE_FOLDER_READONLY)
1221 cp = _("Open mailbox in read-only mode");
1223 cp = _("Open mailbox");
1227 unset_option (OPTNEWS);
1228 if (op == OP_MAIN_CHANGE_GROUP ||
1229 op == OP_MAIN_CHANGE_GROUP_READONLY)
1231 set_option (OPTNEWS);
1232 if (!(CurrentNewsSrv = mutt_select_newsserver (NewsServer)))
1235 cp = _("Open newsgroup in read-only mode");
1237 cp = _("Open newsgroup");
1242 mutt_buffy (buf, sizeof (buf));
1244 if ( op == OP_SIDEBAR_OPEN ) {
1247 strncpy( buf, CurBuffy->path, sizeof(buf) );
1248 } else if (mutt_enter_fname (cp, buf, sizeof (buf), &menu->redraw, 1) == -1)
1252 CLEARLINE (LINES-1);
1257 if (option (OPTNEWS))
1259 unset_option (OPTNEWS);
1260 nntp_expand_path (buf, sizeof (buf), &CurrentNewsSrv->conn->account);
1264 mutt_expand_path (buf, sizeof (buf));
1266 if (mx_get_magic (buf) <= 0)
1268 mutt_error (_("%s is not a mailbox."), buf);
1276 mutt_str_replace (&LastFolder, Context->path);
1277 oldcount = Context ? Context->msgcount : 0;
1279 if ((check = mx_close_mailbox (Context, &index_hint)) != 0)
1281 if (check == M_NEW_MAIL || check == M_REOPENED)
1282 update_index (menu, Context, check, oldcount, index_hint);
1284 set_option (OPTSEARCHINVALID);
1285 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1293 /* Set CurrentMenu to MENU_MAIN before executing any folder
1294 * hooks so that all the index menu functions are available to
1298 CurrentMenu = MENU_MAIN;
1299 mutt_folder_hook (buf);
1301 if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL)
1303 menu->current = ci_first_message ();
1309 /* mutt_buffy_check() must be done with mail-reader mode! */
1310 menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
1311 (Context && (Context->magic == M_NNTP)) ? IndexNewsHelp : IndexHelp);
1313 mutt_clear_error ();
1314 mutt_buffy_check(1); /* force the buffy check after we have changed
1316 menu->redraw = REDRAW_FULL;
1317 set_option (OPTSEARCHINVALID);
1320 case OP_DISPLAY_MESSAGE:
1321 case OP_DISPLAY_HEADERS: /* don't weed the headers */
1326 * toggle the weeding of headers so that a user can press the key
1327 * again while reading the message.
1329 if (op == OP_DISPLAY_HEADERS)
1330 toggle_option (OPTWEED);
1332 unset_option (OPTNEEDRESORT);
1334 if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed)
1336 mutt_uncollapse_thread (Context, CURHDR);
1337 mutt_set_virtual (Context);
1338 if (option (OPTUNCOLLAPSEJUMP))
1339 menu->current = mutt_thread_next_unread (Context, CURHDR);
1342 if ((op = mutt_display_message (CURHDR)) == -1)
1344 unset_option (OPTNEEDRESORT);
1348 menu->menu = MENU_PAGER;
1349 menu->oldcurrent = menu->current;
1355 if (menu->menu == MENU_MAIN && attach_msg)
1361 if ((menu->menu == MENU_MAIN)
1362 && (query_quadoption (OPT_QUIT,
1363 _("Exit Mutt without saving?")) == M_YES))
1367 mx_fastclose_mailbox (Context);
1379 mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
1380 /* if we were in the pager, redisplay the message */
1381 if (menu->menu == MENU_PAGER)
1383 op = OP_DISPLAY_MESSAGE;
1387 menu->redraw = REDRAW_CURRENT;
1390 case OP_MAIN_NEXT_UNDELETED:
1394 if (menu->current >= Context->vcount - 1)
1396 if (menu->menu == MENU_MAIN)
1397 mutt_error _("You are on the last message.");
1400 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1402 menu->current = menu->oldcurrent;
1403 if (menu->menu == MENU_MAIN)
1404 mutt_error _("No undeleted messages.");
1406 else if (menu->menu == MENU_PAGER)
1408 op = OP_DISPLAY_MESSAGE;
1412 menu->redraw = REDRAW_MOTION;
1419 if (menu->current >= Context->vcount - 1)
1421 if (menu->menu == MENU_MAIN)
1422 mutt_error _("You are on the last message.");
1426 if (menu->menu == MENU_PAGER)
1428 op = OP_DISPLAY_MESSAGE;
1432 menu->redraw = REDRAW_MOTION;
1435 case OP_MAIN_PREV_UNDELETED:
1439 if (menu->current < 1)
1441 mutt_error _("You are on the first message.");
1444 if ((menu->current = ci_previous_undeleted (menu->current)) == -1)
1446 menu->current = menu->oldcurrent;
1447 if (menu->menu == MENU_MAIN)
1448 mutt_error _("No undeleted messages.");
1450 else if (menu->menu == MENU_PAGER)
1452 op = OP_DISPLAY_MESSAGE;
1456 menu->redraw = REDRAW_MOTION;
1463 if (menu->current < 1)
1465 if (menu->menu == MENU_MAIN) mutt_error _("You are on the first message.");
1469 if (menu->menu == MENU_PAGER)
1471 op = OP_DISPLAY_MESSAGE;
1475 menu->redraw = REDRAW_MOTION;
1478 case OP_DECRYPT_COPY:
1479 case OP_DECRYPT_SAVE:
1483 case OP_COPY_MESSAGE:
1485 case OP_DECODE_COPY:
1486 case OP_DECODE_SAVE:
1489 if (mutt_save_message (tag ? NULL : CURHDR,
1490 (op == OP_DECRYPT_SAVE) ||
1491 (op == OP_SAVE) || (op == OP_DECODE_SAVE),
1492 (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
1493 (op == OP_DECRYPT_SAVE) || (op == OP_DECRYPT_COPY) ||
1495 &menu->redraw) == 0 &&
1496 (op == OP_SAVE || op == OP_DECODE_SAVE || op == OP_DECRYPT_SAVE)
1500 menu->redraw |= REDRAW_INDEX;
1501 else if (option (OPTRESOLVE))
1503 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1505 menu->current = menu->oldcurrent;
1506 menu->redraw |= REDRAW_CURRENT;
1509 menu->redraw |= REDRAW_MOTION_RESYNCH;
1512 menu->redraw |= REDRAW_CURRENT;
1516 case OP_MAIN_NEXT_NEW:
1517 case OP_MAIN_NEXT_UNREAD:
1518 case OP_MAIN_PREV_NEW:
1519 case OP_MAIN_PREV_UNREAD:
1520 case OP_MAIN_NEXT_NEW_THEN_UNREAD:
1521 case OP_MAIN_PREV_NEW_THEN_UNREAD:
1524 int first_unread = -1;
1532 for (j = 0; j != Context->vcount; j++)
1534 #define CURHDRi Context->hdrs[Context->v2r[i]]
1535 if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_NEXT_NEW_THEN_UNREAD)
1538 if (i > Context->vcount - 1)
1540 mutt_message _("Search wrapped to top.");
1549 mutt_message _("Search wrapped to bottom.");
1550 i = Context->vcount - 1;
1554 if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS)
1556 if (UNREAD (CURHDRi) && first_unread == -1)
1558 if (UNREAD (CURHDRi) == 1 && first_new == -1)
1561 else if ((!CURHDRi->deleted && !CURHDRi->read))
1563 if (first_unread == -1)
1565 if ((!CURHDRi->old) && first_new == -1)
1569 if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
1572 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1573 op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1578 if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
1579 op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1581 menu->current = first_new;
1582 else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
1583 op == OP_MAIN_NEXT_NEW_THEN_UNREAD || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
1584 && first_unread != -1)
1585 menu->current = first_unread;
1587 if (menu->current == -1)
1589 menu->current = menu->oldcurrent;
1590 mutt_error ("%s%s.", (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW) ? _("No new messages") : _("No unread messages"),
1591 Context->pattern ? _(" in this limited view") : "");
1593 else if (menu->menu == MENU_PAGER)
1595 op = OP_DISPLAY_MESSAGE;
1599 menu->redraw = REDRAW_MOTION;
1602 case OP_FLAG_MESSAGE:
1609 if (Context->magic == M_POP)
1612 mutt_error _("Can't change 'important' flag on POP server.");
1618 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1622 if (Context->magic == M_NNTP)
1625 mutt_error _("Can't change 'important' flag on NNTP server.");
1632 for (j = 0; j < Context->vcount; j++)
1634 if (Context->hdrs[Context->v2r[j]]->tagged)
1635 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
1636 M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
1639 menu->redraw |= REDRAW_INDEX;
1643 mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
1644 if (option (OPTRESOLVE))
1646 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1648 menu->current = menu->oldcurrent;
1649 menu->redraw = REDRAW_CURRENT;
1652 menu->redraw = REDRAW_MOTION_RESYNCH;
1655 menu->redraw = REDRAW_CURRENT;
1657 menu->redraw |= REDRAW_STATUS;
1667 CHECK_IMAP_ACL(IMAP_ACL_SEEN);
1672 for (j = 0; j < Context->vcount; j++)
1674 if (Context->hdrs[Context->v2r[j]]->tagged)
1676 if (Context->hdrs[Context->v2r[j]]->read ||
1677 Context->hdrs[Context->v2r[j]]->old)
1678 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW, 1);
1680 mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ, 1);
1683 menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
1687 if (CURHDR->read || CURHDR->old)
1688 mutt_set_flag (Context, CURHDR, M_NEW, 1);
1690 mutt_set_flag (Context, CURHDR, M_READ, 1);
1692 if (option (OPTRESOLVE))
1694 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1696 menu->current = menu->oldcurrent;
1697 menu->redraw = REDRAW_CURRENT;
1700 menu->redraw = REDRAW_MOTION_RESYNCH;
1703 menu->redraw = REDRAW_CURRENT;
1704 menu->redraw |= REDRAW_STATUS;
1708 case OP_TOGGLE_WRITE:
1711 if (mx_toggle_write (Context) == 0)
1712 menu->redraw |= REDRAW_STATUS;
1715 case OP_MAIN_NEXT_THREAD:
1716 case OP_MAIN_NEXT_SUBTHREAD:
1717 case OP_MAIN_PREV_THREAD:
1718 case OP_MAIN_PREV_SUBTHREAD:
1724 case OP_MAIN_NEXT_THREAD:
1725 menu->current = mutt_next_thread (CURHDR);
1728 case OP_MAIN_NEXT_SUBTHREAD:
1729 menu->current = mutt_next_subthread (CURHDR);
1732 case OP_MAIN_PREV_THREAD:
1733 menu->current = mutt_previous_thread (CURHDR);
1736 case OP_MAIN_PREV_SUBTHREAD:
1737 menu->current = mutt_previous_subthread (CURHDR);
1741 if (menu->current < 0)
1743 menu->current = menu->oldcurrent;
1744 if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
1745 mutt_error _("No more threads.");
1747 mutt_error _("You are on the first thread.");
1749 else if (menu->menu == MENU_PAGER)
1751 op = OP_DISPLAY_MESSAGE;
1755 menu->redraw = REDRAW_MOTION;
1758 case OP_MAIN_PARENT_MESSAGE:
1763 if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0)
1765 menu->current = menu->oldcurrent;
1767 else if (menu->menu == MENU_PAGER)
1769 op = OP_DISPLAY_MESSAGE;
1773 menu->redraw = REDRAW_MOTION;
1776 case OP_MAIN_SET_FLAG:
1777 case OP_MAIN_CLEAR_FLAG:
1784 CHECK_IMAP_ACL(IMAP_ACL_WRITE);
1787 if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) == 0)
1789 menu->redraw = REDRAW_STATUS;
1791 menu->redraw |= REDRAW_INDEX;
1792 else if (option (OPTRESOLVE))
1794 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1796 menu->current = menu->oldcurrent;
1797 menu->redraw |= REDRAW_CURRENT;
1800 menu->redraw |= REDRAW_MOTION_RESYNCH;
1803 menu->redraw |= REDRAW_CURRENT;
1807 case OP_MAIN_COLLAPSE_THREAD:
1811 if ((Sort & SORT_MASK) != SORT_THREADS)
1813 mutt_error _("Threading is not enabled.");
1817 if (CURHDR->collapsed)
1819 menu->current = mutt_uncollapse_thread (Context, CURHDR);
1820 mutt_set_virtual (Context);
1821 if (option (OPTUNCOLLAPSEJUMP))
1822 menu->current = mutt_thread_next_unread (Context, CURHDR);
1824 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1826 menu->current = mutt_collapse_thread (Context, CURHDR);
1827 mutt_set_virtual (Context);
1831 mutt_error _("Thread contains unread messages.");
1835 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1839 case OP_MAIN_COLLAPSE_ALL:
1843 if ((Sort & SORT_MASK) != SORT_THREADS)
1845 mutt_error _("Threading is not enabled.");
1851 THREAD *thread, *top;
1854 if (CURHDR->collapsed)
1855 final = mutt_uncollapse_thread (Context, CURHDR);
1856 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (CURHDR))
1857 final = mutt_collapse_thread (Context, CURHDR);
1859 final = CURHDR->virtual;
1861 base = Context->hdrs[Context->v2r[final]];
1863 top = Context->tree;
1864 Context->collapsed = !Context->collapsed;
1865 while ((thread = top) != NULL)
1867 while (!thread->message)
1868 thread = thread->child;
1869 h = thread->message;
1871 if (h->collapsed != Context->collapsed)
1874 mutt_uncollapse_thread (Context, h);
1875 else if (option (OPTCOLLAPSEUNREAD) || !UNREAD (h))
1876 mutt_collapse_thread (Context, h);
1881 mutt_set_virtual (Context);
1882 for (j = 0; j < Context->vcount; j++)
1884 if (Context->hdrs[Context->v2r[j]]->index == base->index)
1891 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1895 /* --------------------------------------------------------------------
1896 * These functions are invoked directly from the internal-pager
1899 case OP_BOUNCE_MESSAGE:
1904 ci_bounce_message (tag ? NULL : CURHDR, &menu->redraw);
1907 case OP_CREATE_ALIAS:
1909 mutt_create_alias (Context && Context->vcount ? CURHDR->env : NULL, NULL);
1910 MAYBE_REDRAW (menu->redraw);
1911 menu->redraw |= REDRAW_CURRENT;
1916 mutt_query_menu (NULL, 0);
1917 MAYBE_REDRAW (menu->redraw);
1920 case OP_PURGE_MESSAGE:
1928 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
1933 mutt_tag_set_flag (M_DELETE, 1);
1934 mutt_tag_set_flag (M_PURGED, (op != OP_PURGE_MESSAGE) ? 0 : 1);
1935 if (option (OPTDELETEUNTAG))
1936 mutt_tag_set_flag (M_TAG, 0);
1937 menu->redraw = REDRAW_INDEX;
1941 mutt_set_flag (Context, CURHDR, M_DELETE, 1);
1942 mutt_set_flag (Context, CURHDR, M_PURGED,
1943 (op != OP_PURGE_MESSAGE) ? 0 : 1);
1944 if (option (OPTDELETEUNTAG))
1945 mutt_set_flag (Context, CURHDR, M_TAG, 0);
1946 if (option (OPTRESOLVE))
1948 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1950 menu->current = menu->oldcurrent;
1951 menu->redraw = REDRAW_CURRENT;
1953 else if (menu->menu == MENU_PAGER)
1955 op = OP_DISPLAY_MESSAGE;
1959 menu->redraw |= REDRAW_MOTION_RESYNCH;
1962 menu->redraw = REDRAW_CURRENT;
1964 menu->redraw |= REDRAW_STATUS;
1967 case OP_DELETE_THREAD:
1968 case OP_DELETE_SUBTHREAD:
1975 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
1978 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 1,
1979 op == OP_DELETE_THREAD ? 0 : 1);
1983 if (option (OPTDELETEUNTAG))
1984 mutt_thread_set_flag (CURHDR, M_TAG, 0,
1985 op == OP_DELETE_THREAD ? 0 : 1);
1986 if (option (OPTRESOLVE))
1987 if ((menu->current = ci_next_undeleted (menu->current)) == -1)
1988 menu->current = menu->oldcurrent;
1989 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
1995 if (Context && Context->magic == M_NNTP)
1997 if (mutt_newsgroup_catchup (CurrentNewsSrv,
1998 ((NNTP_DATA *)Context->data)->group))
1999 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2004 case OP_DISPLAY_ADDRESS:
2008 mutt_display_address (CURHDR->env);
2011 case OP_ENTER_COMMAND:
2013 CurrentMenu = MENU_MAIN;
2014 mutt_enter_command ();
2015 mutt_check_rescore (Context);
2016 if (option (OPTFORCEREDRAWINDEX))
2017 menu->redraw = REDRAW_FULL;
2018 unset_option (OPTFORCEREDRAWINDEX);
2019 unset_option (OPTFORCEREDRAWPAGER);
2022 case OP_EDIT_MESSAGE:
2030 if (Context->magic == M_POP)
2033 mutt_error _("Can't edit message on POP server.");
2039 CHECK_IMAP_ACL(IMAP_ACL_INSERT);
2043 if (Context->magic == M_NNTP)
2046 mutt_error _("Can't edit message on newsserver.");
2051 mutt_edit_message (Context, tag ? NULL : CURHDR);
2052 menu->redraw = REDRAW_FULL;
2056 case OP_FORWARD_MESSAGE:
2061 ci_send_message (SENDFORWARD, NULL, NULL, Context, tag ? NULL : CURHDR);
2062 menu->redraw = REDRAW_FULL;
2066 case OP_FORGET_PASSPHRASE:
2067 crypt_forget_passphrase ();
2070 case OP_GROUP_REPLY:
2075 ci_send_message (SENDREPLY|SENDGROUPREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2076 menu->redraw = REDRAW_FULL;
2084 ci_send_message (SENDREPLY|SENDLISTREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2085 menu->redraw = REDRAW_FULL;
2091 ci_send_message (0, NULL, NULL, Context, NULL);
2092 menu->redraw = REDRAW_FULL;
2096 if (!(WithCrypto & APPLICATION_PGP))
2099 ci_send_message (SENDKEY, NULL, NULL, NULL, NULL);
2100 menu->redraw = REDRAW_FULL;
2104 case OP_EXTRACT_KEYS:
2109 crypt_extract_keys_from_messages(tag ? NULL : CURHDR);
2110 menu->redraw = REDRAW_FULL;
2114 case OP_CHECK_TRADITIONAL:
2115 if (!(WithCrypto & APPLICATION_PGP))
2119 mutt_check_traditional_pgp (tag ? NULL : CURHDR, &menu->redraw);
2120 if (menu->menu == MENU_PAGER)
2122 op = OP_DISPLAY_MESSAGE;
2131 mutt_pipe_message (tag ? NULL : CURHDR);
2132 MAYBE_REDRAW (menu->redraw);
2139 mutt_print_message (tag ? NULL : CURHDR);
2142 case OP_MAIN_READ_THREAD:
2143 case OP_MAIN_READ_SUBTHREAD:
2150 CHECK_IMAP_ACL(IMAP_ACL_SEEN);
2153 rc = mutt_thread_set_flag (CURHDR, M_READ, 1,
2154 op == OP_MAIN_READ_THREAD ? 0 : 1);
2158 if (option (OPTRESOLVE))
2160 if ((menu->current = (op == OP_MAIN_READ_THREAD ?
2161 mutt_next_thread (CURHDR) : mutt_next_subthread (CURHDR))) == -1)
2162 menu->current = menu->oldcurrent;
2164 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2168 case OP_RECALL_MESSAGE:
2171 ci_send_message (SENDPOSTPONED, NULL, NULL, Context, NULL);
2172 menu->redraw = REDRAW_FULL;
2183 for (j = 0; j < Context->vcount; j++)
2185 if (Context->hdrs[Context->v2r[j]]->tagged)
2186 mutt_resend_message (NULL, Context, Context->hdrs[Context->v2r[j]]);
2190 mutt_resend_message (NULL, Context, CURHDR);
2192 menu->redraw = REDRAW_FULL;
2198 case OP_FORWARD_TO_GROUP:
2201 if (op != OP_FOLLOWUP || !CURHDR->env->followup_to ||
2202 mutt_strcasecmp (CURHDR->env->followup_to, "poster") ||
2203 query_quadoption (OPT_FOLLOWUPTOPOSTER,_("Reply by mail as poster prefers?")) != M_YES)
2205 if (Context && Context->magic == M_NNTP &&
2206 !((NNTP_DATA *)Context->data)->allowed &&
2207 query_quadoption (OPT_TOMODERATED, _("Posting to this group not allowed, may be moderated. Continue?")) != M_YES)
2210 ci_send_message (SENDNEWS, NULL, NULL, Context, NULL);
2214 if (op == OP_FOLLOWUP)
2215 ci_send_message (SENDNEWS|SENDREPLY, NULL, NULL, Context,
2216 tag ? NULL : CURHDR);
2218 ci_send_message (SENDNEWS|SENDFORWARD, NULL, NULL, Context,
2219 tag ? NULL : CURHDR);
2221 menu->redraw = REDRAW_FULL;
2231 ci_send_message (SENDREPLY, NULL, NULL, Context, tag ? NULL : CURHDR);
2232 menu->redraw = REDRAW_FULL;
2235 case OP_SHELL_ESCAPE:
2237 mutt_shell_escape ();
2238 MAYBE_REDRAW (menu->redraw);
2242 case OP_TAG_SUBTHREAD:
2246 rc = mutt_thread_set_flag (CURHDR, M_TAG, !CURHDR->tagged,
2247 op == OP_TAG_THREAD ? 0 : 1);
2251 if (option (OPTRESOLVE))
2253 menu->current = mutt_next_thread (CURHDR);
2255 if (menu->current == -1)
2256 menu->current = menu->oldcurrent;
2258 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2269 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2274 mutt_tag_set_flag (M_DELETE, 0);
2275 mutt_tag_set_flag (M_PURGED, 0);
2276 menu->redraw = REDRAW_INDEX;
2280 mutt_set_flag (Context, CURHDR, M_DELETE, 0);
2281 mutt_set_flag (Context, CURHDR, M_PURGED, 0);
2282 if (option (OPTRESOLVE) && menu->current < Context->vcount - 1)
2285 menu->redraw = REDRAW_MOTION_RESYNCH;
2288 menu->redraw = REDRAW_CURRENT;
2290 menu->redraw |= REDRAW_STATUS;
2293 case OP_UNDELETE_THREAD:
2294 case OP_UNDELETE_SUBTHREAD:
2301 CHECK_IMAP_ACL(IMAP_ACL_DELETE);
2304 rc = mutt_thread_set_flag (CURHDR, M_DELETE, 0,
2305 op == OP_UNDELETE_THREAD ? 0 : 1)
2306 + mutt_thread_set_flag (CURHDR, M_PURGED, 0,
2307 op == OP_UNDELETE_THREAD ? 0 : 1);
2311 if (option (OPTRESOLVE))
2313 if (op == OP_UNDELETE_THREAD)
2314 menu->current = mutt_next_thread (CURHDR);
2316 menu->current = mutt_next_subthread (CURHDR);
2318 if (menu->current == -1)
2319 menu->current = menu->oldcurrent;
2321 menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
2333 case OP_VIEW_ATTACHMENTS:
2336 mutt_view_attachments (CURHDR);
2337 if (CURHDR->attach_del)
2338 Context->changed = 1;
2339 menu->redraw = REDRAW_FULL;
2349 case OP_SIDEBAR_SCROLL_UP:
2350 case OP_SIDEBAR_SCROLL_DOWN:
2351 case OP_SIDEBAR_NEXT:
2352 case OP_SIDEBAR_PREV:
2353 scroll_sidebar(op, menu->menu);
2356 if (menu->menu == MENU_MAIN)
2357 km_error_key (MENU_MAIN);
2360 if (menu->menu == MENU_PAGER)
2362 menu->menu = MENU_MAIN;
2363 menu->redraw = REDRAW_FULL;
2365 set_option (OPTWEED); /* turn header weeding back on. */
2373 /* Close all open IMAP connections */
2378 /* Close all open NNTP connections */
2383 mutt_menuDestroy (&menu);
2387 void mutt_set_header_color (CONTEXT *ctx, HEADER *curhdr)
2394 for (color = ColorIndexList; color; color = color->next)
2395 if (mutt_pattern_exec (color->color_pattern, M_MATCH_FULL_ADDRESS, ctx, curhdr))
2397 curhdr->pair = color->pair;
2400 curhdr->pair = ColorDefs[MT_COLOR_NORMAL];