]> granicus.if.org Git - mutt/commitdiff
Equivalent mutt_buffy, but readable code
authorAron Griffis <agriffis@n01se.net>
Tue, 21 Apr 2009 19:10:28 +0000 (15:10 -0400)
committerAron Griffis <agriffis@n01se.net>
Tue, 21 Apr 2009 19:10:28 +0000 (15:10 -0400)
Signed-off-by: Aron Griffis <agriffis@n01se.net>
buffy.c

diff --git a/buffy.c b/buffy.c
index 0e100e8d3c3565df389ad0af9c2a9c8ca243bac9..0c851b5f7496c9b12f7ffd34a43720d58c70f870 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -508,57 +508,30 @@ int mutt_buffy_notify (void)
  */
 void mutt_buffy (char *s, size_t slen)
 {
-  int count;
   BUFFY *tmp = Incoming;
+  int pass, found = 0;
 
   mutt_expand_path (s, slen);
-  switch (mutt_buffy_check (0))
-  {
-  case 0:
-
-    *s = '\0';
-    break;
-
-  case 1:
-
-    while (tmp && !tmp->new)
-      tmp = tmp->next;
-    if (!tmp)
-    {
-      *s = '\0';
-      mutt_buffy_check (1); /* buffy was wrong - resync things */
-      break;
-    }
-    mutt_expand_path (tmp->path, sizeof (tmp->path));
-    strfcpy (s, tmp->path, slen);
-    mutt_pretty_mailbox (s, slen);
-    break;
 
-  default:
-    
-    count = 0;
-    while (count < 3)
-    {
-      mutt_expand_path (tmp->path, sizeof (tmp->path));
-      if (mutt_strcmp (s, tmp->path) == 0)
-       count++;
-      else if (count && tmp->new)
-       break;
-      tmp = tmp->next;
-      if (!tmp)
+  if (mutt_buffy_check (0)) 
+  {
+    for (pass = 0; pass < 2; pass++)
+      for (tmp = Incoming; tmp; tmp = tmp->next) 
       {
-       tmp = Incoming;
-       count++;
+       mutt_expand_path (tmp->path, sizeof (tmp->path));
+       if ((found || pass) && tmp->new) 
+       {
+         strfcpy (s, tmp->path, slen);
+         mutt_pretty_mailbox (s, slen);
+         return;
+       }
+       if (mutt_strcmp (s, tmp->path) == 0)
+         found = 1;
       }
-    }
-    if (count >= 3)
-    {
-      *s = '\0';
-      mutt_buffy_check (1); /* buffy was wrong - resync things */
-      break;
-    }
-    strfcpy (s, tmp->path, slen);
-    mutt_pretty_mailbox (s, slen);
-    break;
+
+    mutt_buffy_check (1); /* buffy was wrong - resync things */
   }
+
+  /* no folders with new mail */
+  *s = '\0';
 }