*** /root/mutt-1.5.17/curs_main.c	2008-06-07 10:52:39.000000000 +0200
--- curs_main.c	2008-07-19 00:29:57.000000000 +0200
*************** int mutt_index_menu (void)
*** 1060,1065 ****
--- 1060,1158 ----
  	  menu->redraw = REDRAW_FULL;
  	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;
+         CHECK_VISIBLE;
+
+ 	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;
+           op = OP_MAIN_NEXT_UNREAD_MAILBOX;
+ #if 0
+           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") : "");
+ #endif
+         }
+         else
+         {
+            if (menu->menu == MENU_PAGER)
+            {
+              op = OP_DISPLAY_MESSAGE;
+              continue;
+            }
+            else
+              menu->redraw = REDRAW_MOTION;
+            break;
+         }
+       }
+
        case OP_SIDEBAR_OPEN:
        case OP_MAIN_CHANGE_FOLDER:
        case OP_MAIN_NEXT_UNREAD_MAILBOX:
*************** int mutt_index_menu (void)
*** 1437,1528 ****
  	}
  	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;
-         CHECK_VISIBLE;
-
- 	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;
--- 1530,1536 ----

