+#ifdef USE_COMPRESSED
+ if (Context->compressinfo && Context->realpath)
+ mutt_str_replace (&LastFolder, Context->realpath);
+ else
+#endif
+
+ mutt_str_replace (&LastFolder, Context->path);
+ oldcount = Context ? Context->msgcount : 0;
+
+ if ((check = mx_close_mailbox (Context, &index_hint)) != 0) {
+ if (check == M_NEW_MAIL || check == M_REOPENED)
+ update_index (menu, Context, check, oldcount, index_hint);
+
+ set_option (OPTSEARCHINVALID);
+ menu->redraw = REDRAW_INDEX | REDRAW_STATUS;
+ break;
+ }
+ FREE (&Context);
+ }
+
+ mutt_sleep (0);
+
+ /* Set CurrentMenu to MENU_MAIN before executing any folder
+ * hooks so that all the index menu functions are available to
+ * the exec command.
+ */
+
+ CurrentMenu = MENU_MAIN;
+ mutt_folder_hook (buf);
+
+ if ((Context = mx_open_mailbox (buf, flags, NULL)) != NULL) {
+ menu->current = ci_first_message ();
+ }
+ else
+ menu->current = 0;
+
+#ifdef USE_NNTP
+ /* mutt_buffy_check() must be done with mail-reader mode! */
+ menu->help = mutt_compile_help (helpstr, sizeof (helpstr), MENU_MAIN,
+ (Context
+ && (Context->magic ==
+ M_NNTP)) ? IndexNewsHelp :
+ IndexHelp);
+#endif
+ mutt_clear_error ();
+ mutt_buffy_check (1); /* force the buffy check after we have changed
+ the folder */
+ menu->redraw = REDRAW_FULL;
+ set_option (OPTSEARCHINVALID);
+ break;
+
+ case OP_DISPLAY_MESSAGE:
+ case OP_DISPLAY_HEADERS: /* don't weed the headers */
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ /*
+ * toggle the weeding of headers so that a user can press the key
+ * again while reading the message.
+ */
+ if (op == OP_DISPLAY_HEADERS)
+ toggle_option (OPTWEED);
+
+ unset_option (OPTNEEDRESORT);
+
+ if ((Sort & SORT_MASK) == SORT_THREADS && CURHDR->collapsed) {
+ mutt_uncollapse_thread (Context, CURHDR);
+ mutt_set_virtual (Context);
+ if (option (OPTUNCOLLAPSEJUMP))
+ menu->current = mutt_thread_next_unread (Context, CURHDR);
+ }
+
+ if ((op = mutt_display_message (CURHDR)) == -1) {
+ unset_option (OPTNEEDRESORT);
+ break;
+ }
+
+ menu->menu = MENU_PAGER;
+ menu->oldcurrent = menu->current;
+ continue;
+
+ case OP_EXIT:
+
+ close = op;
+ if (menu->menu == MENU_MAIN && attach_msg) {
+ done = 1;
+ break;
+ }
+
+ if ((menu->menu == MENU_MAIN)
+ && (query_quadoption (OPT_QUIT,
+ _("Exit Mutt-ng without saving?")) == M_YES))
+ {
+ if (Context) {
+ mx_fastclose_mailbox (Context);
+ FREE (&Context);
+ }
+ done = 1;
+ }
+ break;
+
+ case OP_EDIT_TYPE:
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ CHECK_ATTACH;
+ mutt_edit_content_type (CURHDR, CURHDR->content, NULL);
+ /* if we were in the pager, redisplay the message */
+ if (menu->menu == MENU_PAGER) {
+ op = OP_DISPLAY_MESSAGE;
+ continue;
+ }
+ else
+ menu->redraw = REDRAW_CURRENT;
+ break;
+
+ case OP_MAIN_BREAK_THREAD:
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ CHECK_READONLY;
+
+ if ((Sort & SORT_MASK) != SORT_THREADS)
+ mutt_error (_("Threading is not enabled."));
+
+ else {
+ {
+ HEADER *oldcur = CURHDR;
+
+ mutt_break_thread (CURHDR);
+ mutt_sort_headers (Context, 1);
+ menu->current = oldcur->virtual;
+ }
+
+ Context->changed = 1;
+ mutt_message _("Thread broken");
+
+ if (menu->menu == MENU_PAGER) {
+ op = OP_DISPLAY_MESSAGE;
+ continue;
+ }
+ else
+ menu->redraw |= REDRAW_INDEX;
+ }
+ break;
+
+ case OP_MAIN_LINK_THREADS:
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ CHECK_READONLY;
+
+ if ((Sort & SORT_MASK) != SORT_THREADS)
+ mutt_error (_("Threading is not enabled."));
+
+ else if (!CURHDR->env->message_id)
+ mutt_error (_("No Message-ID: header available to link thread"));
+
+ else if (!tag && (!Context->last_tag || !Context->last_tag->tagged))
+ mutt_error (_("First, please tag a message to be linked here"));