+ 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"));
+
+ else {
+ HEADER *oldcur = CURHDR;
+
+ if (mutt_link_threads (CURHDR, tag ? NULL : Context->last_tag,
+ Context)) {
+ mutt_sort_headers (Context, 1);
+ menu->current = oldcur->virtual;
+
+ Context->changed = 1;
+ mutt_message _("Threads linked");
+ }
+ else
+ mutt_error (_("No thread linked"));
+ }
+
+ if (menu->menu == MENU_PAGER) {
+ op = OP_DISPLAY_MESSAGE;
+ continue;
+ }
+ else
+ menu->redraw |= REDRAW_STATUS | REDRAW_INDEX;
+ break;
+
+ case OP_MAIN_NEXT_UNDELETED:
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ if (menu->current >= Context->vcount - 1) {
+ if (menu->menu == MENU_MAIN)
+ mutt_error (_("You are on the last message."));
+
+ break;
+ }
+ if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
+ menu->current = menu->oldcurrent;
+ if (menu->menu == MENU_MAIN)
+ mutt_error (_("No undeleted messages."));
+ }
+ else if (menu->menu == MENU_PAGER) {
+ op = OP_DISPLAY_MESSAGE;
+ continue;
+ }
+ else
+ menu->redraw = REDRAW_MOTION;
+ break;
+
+ case OP_NEXT_ENTRY:
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ if (menu->current >= Context->vcount - 1) {
+ if (menu->menu == MENU_MAIN)
+ mutt_error (_("You are on the last message."));
+
+ break;
+ }
+ menu->current++;
+ if (menu->menu == MENU_PAGER) {
+ op = OP_DISPLAY_MESSAGE;
+ continue;
+ }
+ else
+ menu->redraw = REDRAW_MOTION;
+ break;
+
+ case OP_MAIN_PREV_UNDELETED:
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ if (menu->current < 1) {
+ mutt_error (_("You are on the first message."));
+
+ break;
+ }
+ if ((menu->current = ci_previous_undeleted (menu->current)) == -1) {
+ menu->current = menu->oldcurrent;
+ if (menu->menu == MENU_MAIN)
+ mutt_error (_("No undeleted messages."));
+ }
+ else if (menu->menu == MENU_PAGER) {
+ op = OP_DISPLAY_MESSAGE;
+ continue;
+ }
+ else
+ menu->redraw = REDRAW_MOTION;
+ break;
+
+ case OP_PREV_ENTRY:
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ if (menu->current < 1) {
+ if (menu->menu == MENU_MAIN)
+ mutt_error (_("You are on the first message."));
+
+ break;
+ }
+ menu->current--;
+ if (menu->menu == MENU_PAGER) {
+ op = OP_DISPLAY_MESSAGE;
+ continue;
+ }
+ else
+ menu->redraw = REDRAW_MOTION;
+ break;
+
+ case OP_DECRYPT_COPY:
+ case OP_DECRYPT_SAVE:
+ if (!WithCrypto)
+ break;
+ /* fall thru */
+ case OP_COPY_MESSAGE:
+ case OP_SAVE:
+ case OP_DECODE_COPY:
+ case OP_DECODE_SAVE:
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ if (mutt_save_message (tag ? NULL : CURHDR,
+ (op == OP_DECRYPT_SAVE) ||
+ (op == OP_SAVE) || (op == OP_DECODE_SAVE),
+ (op == OP_DECODE_SAVE) || (op == OP_DECODE_COPY),
+ (op == OP_DECRYPT_SAVE)
+ || (op == OP_DECRYPT_COPY)
+ || 0, &menu->redraw) == 0 && (op == OP_SAVE
+ || op ==
+ OP_DECODE_SAVE
+ || op ==
+ OP_DECRYPT_SAVE)
+ ) {
+ if (tag)
+ menu->redraw |= REDRAW_INDEX;
+ else if (option (OPTRESOLVE)) {
+ if ((menu->current = ci_next_undeleted (menu->current)) == -1) {
+ menu->current = menu->oldcurrent;
+ menu->redraw |= REDRAW_CURRENT;
+ }
+ else
+ menu->redraw |= REDRAW_MOTION_RESYNCH;
+ }
+ else
+ menu->redraw |= REDRAW_CURRENT;
+ }
+ break;
+
+ case OP_MAIN_NEXT_NEW:
+ case OP_MAIN_NEXT_UNREAD:
+ case OP_MAIN_PREV_NEW:
+ case OP_MAIN_PREV_UNREAD:
+ case OP_MAIN_NEXT_NEW_THEN_UNREAD:
+ case OP_MAIN_PREV_NEW_THEN_UNREAD:
+
+ {
+ int first_unread = -1;
+ int first_new = -1;
+
+ CHECK_MSGCOUNT;