+
+ i = menu->current;
+ menu->current = -1;
+ for (j = 0; j != Context->vcount; j++) {
+#define CURHDRi Context->hdrs[Context->v2r[i]]
+ if (op == OP_MAIN_NEXT_NEW || op == OP_MAIN_NEXT_UNREAD
+ || op == OP_MAIN_NEXT_NEW_THEN_UNREAD) {
+ i++;
+ if (i > Context->vcount - 1) {
+ mutt_message _("Search wrapped to top.");
+
+ i = 0;
+ }
+ }
+ else {
+ i--;
+ if (i < 0) {
+ mutt_message _("Search wrapped to bottom.");
+
+ i = Context->vcount - 1;
+ }
+ }
+
+ if (CURHDRi->collapsed && (Sort & SORT_MASK) == SORT_THREADS) {
+ if (UNREAD (CURHDRi) && first_unread == -1)
+ first_unread = i;
+ if (UNREAD (CURHDRi) == 1 && first_new == -1)
+ first_new = i;
+ }
+ else if ((!CURHDRi->deleted && !CURHDRi->read)) {
+ if (first_unread == -1)
+ first_unread = i;
+ if ((!CURHDRi->old) && first_new == -1)
+ first_new = i;
+ }
+
+ if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD) &&
+ first_unread != -1)
+ break;
+ if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
+ op == OP_MAIN_NEXT_NEW_THEN_UNREAD
+ || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
+ && first_new != -1)
+ break;
+ }
+#undef CURHDRi
+ if ((op == OP_MAIN_NEXT_NEW || op == OP_MAIN_PREV_NEW ||
+ op == OP_MAIN_NEXT_NEW_THEN_UNREAD
+ || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
+ && first_new != -1)
+ menu->current = first_new;
+ else if ((op == OP_MAIN_NEXT_UNREAD || op == OP_MAIN_PREV_UNREAD ||
+ op == OP_MAIN_NEXT_NEW_THEN_UNREAD
+ || op == OP_MAIN_PREV_NEW_THEN_UNREAD)
+ && first_unread != -1)
+ menu->current = first_unread;
+
+ if (menu->current == -1) {
+ menu->current = menu->oldcurrent;
+ mutt_error ("%s%s.",
+ (op == OP_MAIN_NEXT_NEW
+ || op ==
+ OP_MAIN_PREV_NEW) ? _("No new messages") :
+ _("No unread messages"),
+ Context->pattern ? _(" in this limited view") : "");
+ }
+ else if (menu->menu == MENU_PAGER) {
+ op = OP_DISPLAY_MESSAGE;
+ continue;
+ }
+ else
+ menu->redraw = REDRAW_MOTION;
+ break;
+ }
+ case OP_FLAG_MESSAGE:
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ CHECK_READONLY;
+
+ CHECK_MX_ACL (Context, ACL_WRITE, _("Flagging"));
+
+ if (tag) {
+ for (j = 0; j < Context->vcount; j++) {
+ if (Context->hdrs[Context->v2r[j]]->tagged)
+ mutt_set_flag (Context, Context->hdrs[Context->v2r[j]],
+ M_FLAG, !Context->hdrs[Context->v2r[j]]->flagged);
+ }
+
+ menu->redraw |= REDRAW_INDEX;
+ }
+ else {
+ mutt_set_flag (Context, CURHDR, M_FLAG, !CURHDR->flagged);
+ 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;
+ }
+ menu->redraw |= REDRAW_STATUS;
+ break;
+
+ case OP_TOGGLE_NEW:
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ CHECK_READONLY;
+
+ CHECK_MX_ACL (Context, ACL_SEEN, _("Toggling"));
+
+ if (tag) {
+ for (j = 0; j < Context->vcount; j++) {
+ if (Context->hdrs[Context->v2r[j]]->tagged) {
+ if (Context->hdrs[Context->v2r[j]]->read ||
+ Context->hdrs[Context->v2r[j]]->old)
+ mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_NEW,
+ 1);
+ else
+ mutt_set_flag (Context, Context->hdrs[Context->v2r[j]], M_READ,
+ 1);
+ }
+ }
+ menu->redraw = REDRAW_STATUS | REDRAW_INDEX;
+ }
+ else {
+ if (CURHDR->read || CURHDR->old)
+ mutt_set_flag (Context, CURHDR, M_NEW, 1);
+ else
+ mutt_set_flag (Context, CURHDR, M_READ, 1);
+
+ 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;
+ menu->redraw |= REDRAW_STATUS;
+ }
+ break;
+
+ case OP_TOGGLE_WRITE:
+
+ CHECK_MSGCOUNT;
+ if (mx_toggle_write (Context) == 0)
+ menu->redraw |= REDRAW_STATUS;
+ break;
+
+ case OP_MAIN_NEXT_THREAD:
+ case OP_MAIN_NEXT_SUBTHREAD:
+ case OP_MAIN_PREV_THREAD:
+ case OP_MAIN_PREV_SUBTHREAD:
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ switch (op) {
+ case OP_MAIN_NEXT_THREAD:
+ menu->current = mutt_next_thread (CURHDR);
+ break;
+
+ case OP_MAIN_NEXT_SUBTHREAD:
+ menu->current = mutt_next_subthread (CURHDR);
+ break;
+
+ case OP_MAIN_PREV_THREAD:
+ menu->current = mutt_previous_thread (CURHDR);
+ break;
+
+ case OP_MAIN_PREV_SUBTHREAD:
+ menu->current = mutt_previous_subthread (CURHDR);
+ break;
+ }
+
+ if (menu->current < 0) {
+ menu->current = menu->oldcurrent;
+ if (op == OP_MAIN_NEXT_THREAD || op == OP_MAIN_NEXT_SUBTHREAD)
+ mutt_error (_("No more threads."));
+
+ else
+ mutt_error (_("You are on the first thread."));
+ }
+ else if (menu->menu == MENU_PAGER) {
+ op = OP_DISPLAY_MESSAGE;
+ continue;
+ }
+ else
+ menu->redraw = REDRAW_MOTION;
+ break;
+
+ case OP_MAIN_PARENT_MESSAGE:
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+
+ if ((menu->current = mutt_parent_message (Context, CURHDR)) < 0) {
+ menu->current = menu->oldcurrent;
+ }
+ else if (menu->menu == MENU_PAGER) {
+ op = OP_DISPLAY_MESSAGE;
+ continue;
+ }
+ else
+ menu->redraw = REDRAW_MOTION;
+ break;
+
+ case OP_MAIN_SET_FLAG:
+ case OP_MAIN_CLEAR_FLAG:
+
+ CHECK_MSGCOUNT;
+ CHECK_VISIBLE;
+ CHECK_READONLY;
+
+ if (mutt_change_flag (tag ? NULL : CURHDR, (op == OP_MAIN_SET_FLAG)) ==
+ 0) {
+ menu->redraw = REDRAW_STATUS;