]> granicus.if.org Git - neomutt/commitdiff
Buffy STAILQ
authorRichard Russon <rich@flatcap.org>
Fri, 3 Aug 2018 00:15:14 +0000 (01:15 +0100)
committerRichard Russon <rich@flatcap.org>
Fri, 3 Aug 2018 19:42:25 +0000 (20:42 +0100)
browser.c
buffy.c
buffy.h
imap/browse.c
imap/command.c
imap/imap.c
init.c
main.c
notmuch/mutt_notmuch.c
sidebar.c

index bd2ded2e421ab9acf2911937693a92010212e0e1..eafc0b47141b615ee3d2301393f343233e3bbf17 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -832,7 +832,6 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state,
     DIR *dp = NULL;
     struct dirent *de = NULL;
     char buffer[PATH_MAX + SHORT_STRING];
-    struct Buffy *tmp = NULL;
 
     while (stat(d, &s) == -1)
     {
@@ -894,15 +893,19 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state,
       else if (!S_ISREG(s.st_mode))
         continue;
 
-      tmp = Incoming;
-      while (tmp && (mutt_str_strcmp(buffer, tmp->path) != 0))
-        tmp = tmp->next;
-      if (tmp && Context && (mutt_str_strcmp(tmp->realpath, Context->realpath) == 0))
+      struct BuffyNode *np = NULL;
+      STAILQ_FOREACH(np, &BuffyList, entries)
       {
-        tmp->msg_count = Context->msgcount;
-        tmp->msg_unread = Context->unread;
+        if (mutt_str_strcmp(buffer, np->b->path) != 0)
+          break;
+      }
+
+      if (np && Context && (mutt_str_strcmp(np->b->realpath, Context->realpath) == 0))
+      {
+        np->b->msg_count = Context->msgcount;
+        np->b->msg_unread = Context->unread;
       }
-      add_folder(menu, state, de->d_name, NULL, &s, tmp, NULL);
+      add_folder(menu, state, de->d_name, NULL, &s, np->b, NULL);
     }
     closedir(dp);
   }
@@ -920,23 +923,24 @@ static int examine_directory(struct Menu *menu, struct BrowserState *state,
  */
 static int examine_vfolders(struct Menu *menu, struct BrowserState *state)
 {
-  struct Buffy *tmp = Incoming;
-  if (!tmp)
+  if (STAILQ_EMPTY(&BuffyList))
     return -1;
 
   mutt_buffy_check(0);
 
   init_state(state, menu);
 
-  do
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
-    if (mx_is_notmuch(tmp->path))
+    if (mx_is_notmuch(np->b->path))
     {
-      nm_nonctx_get_count(tmp->path, &tmp->msg_count, &tmp->msg_unread);
-      add_folder(menu, state, tmp->path, tmp->desc, NULL, tmp, NULL);
+      nm_nonctx_get_count(np->b->path, &np->b->msg_count, &np->b->msg_unread);
+      add_folder(menu, state, np->b->path, np->b->desc, NULL, np->b, NULL);
       continue;
     }
-  } while ((tmp = tmp->next));
+  }
+
   browser_sort(state);
   return 0;
 }
@@ -973,71 +977,70 @@ static int examine_mailboxes(struct Menu *menu, struct BrowserState *state)
   else
 #endif
   {
-    struct Buffy *tmp = Incoming;
-
     init_state(state, menu);
 
-    if (!Incoming)
+    if (STAILQ_EMPTY(&BuffyList))
       return -1;
     mutt_buffy_check(0);
 
-    do
+    struct BuffyNode *np = NULL;
+    STAILQ_FOREACH(np, &BuffyList, entries)
     {
-      if (Context && (mutt_str_strcmp(tmp->realpath, Context->realpath) == 0))
+      if (Context && (mutt_str_strcmp(np->b->realpath, Context->realpath) == 0))
       {
-        tmp->msg_count = Context->msgcount;
-        tmp->msg_unread = Context->unread;
+        np->b->msg_count = Context->msgcount;
+        np->b->msg_unread = Context->unread;
       }
 
       char buffer[PATH_MAX];
-      mutt_str_strfcpy(buffer, tmp->path, sizeof(buffer));
+      mutt_str_strfcpy(buffer, np->b->path, sizeof(buffer));
       if (BrowserAbbreviateMailboxes)
         mutt_pretty_mailbox(buffer, sizeof(buffer));
 
 #ifdef USE_IMAP
-      if (mx_is_imap(tmp->path))
+      if (mx_is_imap(np->b->path))
       {
-        add_folder(menu, state, buffer, NULL, NULL, tmp, NULL);
+        add_folder(menu, state, buffer, NULL, NULL, np->b, NULL);
         continue;
       }
 #endif
 #ifdef USE_POP
-      if (mx_is_pop(tmp->path))
+      if (mx_is_pop(np->b->path))
       {
-        add_folder(menu, state, buffer, NULL, NULL, tmp, NULL);
+        add_folder(menu, state, buffer, NULL, NULL, np->b, NULL);
         continue;
       }
 #endif
 #ifdef USE_NNTP
-      if (mx_is_nntp(tmp->path))
+      if (mx_is_nntp(np->b->path))
       {
-        add_folder(menu, state, tmp->path, NULL, NULL, tmp, NULL);
+        add_folder(menu, state, np->b->path, NULL, NULL, np->b, NULL);
         continue;
       }
 #endif
-      if (lstat(tmp->path, &s) == -1)
+      if (lstat(np->b->path, &s) == -1)
         continue;
 
       if ((!S_ISREG(s.st_mode)) && (!S_ISDIR(s.st_mode)) && (!S_ISLNK(s.st_mode)))
         continue;
 
-      if (mx_is_maildir(tmp->path))
+      if (mx_is_maildir(np->b->path))
       {
         struct stat st2;
         char md[PATH_MAX];
 
-        snprintf(md, sizeof(md), "%s/new", tmp->path);
+        snprintf(md, sizeof(md), "%s/new", np->b->path);
         if (stat(md, &s) < 0)
           s.st_mtime = 0;
-        snprintf(md, sizeof(md), "%s/cur", tmp->path);
+        snprintf(md, sizeof(md), "%s/cur", np->b->path);
         if (stat(md, &st2) < 0)
           st2.st_mtime = 0;
         if (st2.st_mtime > s.st_mtime)
           s.st_mtime = st2.st_mtime;
       }
 
-      add_folder(menu, state, buffer, NULL, &s, tmp, NULL);
-    } while ((tmp = tmp->next));
+      add_folder(menu, state, buffer, NULL, &s, np->b, NULL);
+    }
   }
   browser_sort(state);
   return 0;
diff --git a/buffy.c b/buffy.c
index 8246b08ad3fba0ce31e1239417cd9a0165bf3b2e..8423b7432f4a264ef334bc15c41912499098e58a 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -66,6 +66,8 @@ time_t BuffyDoneTime = 0; /**< last time we knew for sure how much mail there wa
 static short BuffyCount = 0;  /**< how many boxes with new mail */
 static short BuffyNotify = 0; /**< # of unnotified new boxes */
 
+struct BuffyList BuffyList = STAILQ_HEAD_INITIALIZER(BuffyList);
+
 /**
  * fseek_last_message - Find the last message in the file
  * @param f File to search
@@ -182,7 +184,6 @@ static struct Buffy *buffy_new(const char *path)
   mutt_str_strfcpy(buffy->path, path, sizeof(buffy->path));
   char *r = realpath(path, rp);
   mutt_str_strfcpy(buffy->realpath, r ? rp : path, sizeof(buffy->realpath));
-  buffy->next = NULL;
   buffy->magic = 0;
 
   return buffy;
@@ -490,23 +491,21 @@ static void buffy_check(struct Buffy *tmp, struct stat *contex_sb, bool check_st
  */
 static struct Buffy *buffy_get(const char *path)
 {
-  struct Buffy *cur = NULL;
-  char *epath = NULL;
-
   if (!path)
     return NULL;
 
-  epath = mutt_str_strdup(path);
+  char *epath = mutt_str_strdup(path);
   mutt_expand_path(epath, mutt_str_strlen(epath));
 
-  for (cur = Incoming; cur; cur = cur->next)
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
     /* must be done late because e.g. IMAP delimiter may change */
-    mutt_expand_path(cur->path, sizeof(cur->path));
-    if (mutt_str_strcmp(cur->path, path) == 0)
+    mutt_expand_path(np->b->path, sizeof(np->b->path));
+    if (mutt_str_strcmp(np->b->path, path) == 0)
     {
       FREE(&epath);
-      return cur;
+      return np->b;
     }
   }
 
@@ -553,20 +552,25 @@ void mutt_buffy_cleanup(const char *path, struct stat *st)
  */
 struct Buffy *mutt_find_mailbox(const char *path)
 {
+  if (!path)
+    return NULL;
+
   struct stat sb;
   struct stat tmp_sb;
 
   if (stat(path, &sb) != 0)
     return NULL;
 
-  for (struct Buffy *b = Incoming; b; b = b->next)
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
-    if (stat(b->path, &tmp_sb) == 0 && sb.st_dev == tmp_sb.st_dev &&
-        sb.st_ino == tmp_sb.st_ino)
+    if ((stat(np->b->path, &tmp_sb) == 0) && (sb.st_dev == tmp_sb.st_dev) &&
+        (sb.st_ino == tmp_sb.st_ino))
     {
-      return b;
+      return np->b;
     }
   }
+
   return NULL;
 }
 
@@ -601,7 +605,6 @@ void mutt_update_mailbox(struct Buffy *b)
 int mutt_parse_mailboxes(struct Buffer *path, struct Buffer *s,
                          unsigned long data, struct Buffer *err)
 {
-  struct Buffy **b = NULL;
   char buf[PATH_MAX];
   struct stat sb;
   char f1[PATH_MAX];
@@ -639,32 +642,33 @@ int mutt_parse_mailboxes(struct Buffer *path, struct Buffer *s,
 
     /* avoid duplicates */
     p = realpath(buf, f1);
-    for (b = &Incoming; *b; b = &((*b)->next))
+    struct BuffyNode *np = NULL;
+    STAILQ_FOREACH(np, &BuffyList, entries)
     {
-      if (mutt_str_strcmp(p ? p : buf, (*b)->realpath) == 0)
+      if (mutt_str_strcmp(p ? p : buf, np->b->realpath) == 0)
       {
-        mutt_debug(3, "mailbox '%s' already registered as '%s'\n", buf, (*b)->path);
+        mutt_debug(3, "mailbox '%s' already registered as '%s'\n", buf, np->b->path);
         break;
       }
     }
 
-    if (*b)
+    if (np)
     {
       FREE(&desc);
       continue;
     }
 
-    *b = buffy_new(buf);
+    struct Buffy *b = buffy_new(buf);
 
-    (*b)->new = false;
-    (*b)->notified = true;
-    (*b)->newly_created = false;
-    (*b)->desc = desc;
+    b->new = false;
+    b->notified = true;
+    b->newly_created = false;
+    b->desc = desc;
 #ifdef USE_NOTMUCH
-    if (mx_is_notmuch((*b)->path))
+    if (mx_is_notmuch(b->path))
     {
-      (*b)->magic = MUTT_NOTMUCH;
-      (*b)->size = 0;
+      b->magic = MUTT_NOTMUCH;
+      b->size = 0;
     }
     else
 #endif
@@ -673,17 +677,21 @@ int mutt_parse_mailboxes(struct Buffer *path, struct Buffer *s,
        * reading it), the size is set to 0 so that later when we check we see
        * that it increased. without check_mbox_size we probably don't care.
        */
-      if (CheckMboxSize && stat((*b)->path, &sb) == 0 && !test_new_folder((*b)->path))
+      if (CheckMboxSize && stat(b->path, &sb) == 0 && !test_new_folder(b->path))
       {
         /* some systems out there don't have an off_t type */
-        (*b)->size = (off_t) sb.st_size;
+        b->size = (off_t) sb.st_size;
       }
       else
-        (*b)->size = 0;
+        b->size = 0;
     }
 
+    struct BuffyNode *bn = mutt_mem_calloc(1, sizeof(*bn));
+    bn->b = b;
+    STAILQ_INSERT_TAIL(&BuffyList, bn, entries);
+
 #ifdef USE_SIDEBAR
-    mutt_sb_notify_mailbox(*b, 1);
+    mutt_sb_notify_mailbox(b, 1);
 #endif
   }
   return 0;
@@ -729,33 +737,33 @@ int mutt_parse_unmailboxes(struct Buffer *path, struct Buffer *s,
       }
     }
 
-    for (struct Buffy **b = &Incoming; *b;)
+    struct BuffyNode *np = NULL;
+    struct BuffyNode *tmp = NULL;
+    STAILQ_FOREACH_SAFE(np, &BuffyList, entries, tmp)
     {
       /* Decide whether to delete all normal mailboxes or all virtual */
-      bool virt = (((*b)->magic == MUTT_NOTMUCH) && (data & MUTT_VIRTUAL));
-      bool norm = (((*b)->magic != MUTT_NOTMUCH) && !(data & MUTT_VIRTUAL));
+      bool virt = ((np->b->magic == MUTT_NOTMUCH) && (data & MUTT_VIRTUAL));
+      bool norm = ((np->b->magic != MUTT_NOTMUCH) && !(data & MUTT_VIRTUAL));
       bool clear_this = clear_all && (virt || norm);
 
-      if (clear_this || (mutt_str_strcasecmp(buf, (*b)->path) == 0) ||
-          (mutt_str_strcasecmp(buf, (*b)->desc) == 0))
+      if (clear_this || (mutt_str_strcasecmp(buf, np->b->path) == 0) ||
+          (mutt_str_strcasecmp(buf, np->b->desc) == 0))
       {
-        struct Buffy *next = (*b)->next;
 #ifdef USE_SIDEBAR
-        mutt_sb_notify_mailbox(*b, 0);
+        mutt_sb_notify_mailbox(np->b, 0);
 #endif
-        buffy_free(b);
-        *b = next;
+        STAILQ_REMOVE(&BuffyList, np, BuffyNode, entries);
+        buffy_free(&np->b);
+        FREE(&np);
         continue;
       }
-
-      b = &((*b)->next);
     }
   }
   return 0;
 }
 
 /**
- * mutt_buffy_check - Check all Incoming for new mail
+ * mutt_buffy_check - Check all BuffyList for new mail
  * @param force Force flags, see below
  * @retval num Number of mailboxes with new mail
  *
@@ -763,7 +771,7 @@ int mutt_parse_unmailboxes(struct Buffer *path, struct Buffer *s,
  * - MUTT_BUFFY_CHECK_FORCE        ignore BuffyTimeout and check for new mail
  * - MUTT_BUFFY_CHECK_FORCE_STATS  ignore BuffyTimeout and calculate statistics
  *
- * Check all Incoming for new mail and total/new/flagged messages
+ * Check all BuffyList for new mail and total/new/flagged messages
  */
 int mutt_buffy_check(int force)
 {
@@ -780,7 +788,7 @@ int mutt_buffy_check(int force)
 #endif
 
   /* fastest return if there are no mailboxes */
-  if (!Incoming)
+  if (STAILQ_EMPTY(&BuffyList))
     return 0;
 
   t = time(NULL);
@@ -813,8 +821,11 @@ int mutt_buffy_check(int force)
     contex_sb.st_ino = 0;
   }
 
-  for (struct Buffy *b = Incoming; b; b = b->next)
-    buffy_check(b, &contex_sb, check_stats);
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
+  {
+    buffy_check(np->b, &contex_sb, check_stats);
+  }
 
   BuffyDoneTime = BuffyTime;
   return BuffyCount;
@@ -826,7 +837,6 @@ int mutt_buffy_check(int force)
  */
 bool mutt_buffy_list(void)
 {
-  struct Buffy *b = NULL;
   char path[PATH_MAX];
   char buffylist[2 * STRING];
   size_t pos = 0;
@@ -836,13 +846,14 @@ bool mutt_buffy_list(void)
 
   buffylist[0] = '\0';
   pos += strlen(strncat(buffylist, _("New mail in "), sizeof(buffylist) - 1 - pos));
-  for (b = Incoming; b; b = b->next)
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
     /* Is there new mail in this mailbox? */
-    if (!b->new || (have_unnotified && b->notified))
+    if (!np->b->new || (have_unnotified && np->b->notified))
       continue;
 
-    mutt_str_strfcpy(path, b->path, sizeof(path));
+    mutt_str_strfcpy(path, np->b->path, sizeof(path));
     mutt_pretty_mailbox(path, sizeof(path));
 
     if (!first && (MuttMessageWindow->cols >= 7) &&
@@ -855,16 +866,17 @@ bool mutt_buffy_list(void)
       pos += strlen(strncat(buffylist + pos, ", ", sizeof(buffylist) - 1 - pos));
 
     /* Prepend an asterisk to mailboxes not already notified */
-    if (!b->notified)
+    if (!np->b->notified)
     {
       /* pos += strlen (strncat(buffylist + pos, "*", sizeof(buffylist)-1-pos)); */
-      b->notified = true;
+      np->b->notified = true;
       BuffyNotify--;
     }
     pos += strlen(strncat(buffylist + pos, path, sizeof(buffylist) - 1 - pos));
     first = 0;
   }
-  if (!first && b)
+
+  if (!first && np)
   {
     strncat(buffylist + pos, ", ...", sizeof(buffylist) - 1 - pos);
   }
@@ -923,18 +935,19 @@ void mutt_buffy(char *s, size_t slen)
     int found = 0;
     for (int pass = 0; pass < 2; pass++)
     {
-      for (struct Buffy *b = Incoming; b; b = b->next)
+      struct BuffyNode *np = NULL;
+      STAILQ_FOREACH(np, &BuffyList, entries)
       {
-        if (b->magic == MUTT_NOTMUCH) /* only match real mailboxes */
+        if (np->b->magic == MUTT_NOTMUCH) /* only match real mailboxes */
           continue;
-        mutt_expand_path(b->path, sizeof(b->path));
-        if ((found || pass) && b->new)
+        mutt_expand_path(np->b->path, sizeof(np->b->path));
+        if ((found || pass) && np->b->new)
         {
-          mutt_str_strfcpy(s, b->path, slen);
+          mutt_str_strfcpy(s, np->b->path, slen);
           mutt_pretty_mailbox(s, slen);
           return;
         }
-        if (mutt_str_strcmp(s, b->path) == 0)
+        if (mutt_str_strcmp(s, np->b->path) == 0)
           found = 1;
       }
     }
@@ -959,16 +972,17 @@ void mutt_buffy_vfolder(char *buf, size_t buflen)
     bool found = false;
     for (int pass = 0; pass < 2; pass++)
     {
-      for (struct Buffy *b = Incoming; b; b = b->next)
+      struct BuffyNode *np = NULL;
+      STAILQ_FOREACH(np, &BuffyList, entries)
       {
-        if (b->magic != MUTT_NOTMUCH)
+        if (np->b->magic != MUTT_NOTMUCH)
           continue;
-        if ((found || pass) && b->new)
+        if ((found || pass) && np->b->new)
         {
-          mutt_str_strfcpy(buf, b->desc, buflen);
+          mutt_str_strfcpy(buf, np->b->desc, buflen);
           return;
         }
-        if (mutt_str_strcmp(buf, b->path) == 0)
+        if (mutt_str_strcmp(buf, np->b->path) == 0)
           found = true;
       }
     }
diff --git a/buffy.h b/buffy.h
index f86b94c2ad01929247ca76f364322d8592bf0d5c..c7b1e26f38996fa09a3a855c79f85daad9a079de 100644 (file)
--- a/buffy.h
+++ b/buffy.h
@@ -27,6 +27,7 @@
 #include <stdbool.h>
 #include <sys/types.h>
 #include <time.h>
+#include "mutt/mutt.h"
 #include "where.h"
 
 struct Buffer;
@@ -52,7 +53,6 @@ struct Buffy
                             * comparison, and the sidebar */
   char *desc;
   off_t size;
-  struct Buffy *next;
   bool new; /**< mailbox has new mail */
 
   /* These next three are only set when MailCheckStats is set */
@@ -67,7 +67,15 @@ struct Buffy
   time_t stats_last_checked; /**< mtime of mailbox the last time stats where checked. */
 };
 
-WHERE struct Buffy *Incoming;
+struct BuffyNode
+{
+  struct Buffy *b;
+  STAILQ_ENTRY(BuffyNode) entries;
+};
+
+STAILQ_HEAD(BuffyList, BuffyNode);
+
+extern struct BuffyList BuffyList;
 
 #ifdef USE_NOTMUCH
 void mutt_buffy_vfolder(char *buf, size_t buflen);
index 163e0dbcf84d0ec639e75b6789a838949dd6582c..cd7876ffdde4c520e02d1578b4f7dc7bd973ca1f 100644 (file)
@@ -64,7 +64,6 @@ static void add_folder(char delim, char *folder, int noselect, int noinferiors,
   char tmp[PATH_MAX];
   char relpath[PATH_MAX];
   struct ImapMbox mx;
-  struct Buffy *b = NULL;
 
   if (imap_parse_path(state->folder, &mx))
     return;
@@ -114,20 +113,24 @@ static void add_folder(char delim, char *folder, int noselect, int noinferiors,
   (state->entry)[state->entrylen].selectable = !noselect;
   (state->entry)[state->entrylen].inferiors = !noinferiors;
 
-  b = Incoming;
-  while (b && (mutt_str_strcmp(tmp, b->path) != 0))
-    b = b->next;
-  if (b)
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
-    if (Context && (mutt_str_strcmp(b->realpath, Context->realpath) == 0))
+    if (mutt_str_strcmp(tmp, np->b->path) == 0)
+      break;
+  }
+
+  if (np)
+  {
+    if (Context && (mutt_str_strcmp(np->b->realpath, Context->realpath) == 0))
     {
-      b->msg_count = Context->msgcount;
-      b->msg_unread = Context->unread;
+      np->b->msg_count = Context->msgcount;
+      np->b->msg_unread = Context->unread;
     }
     (state->entry)[state->entrylen].has_buffy = true;
-    (state->entry)[state->entrylen].new = b->new;
-    (state->entry)[state->entrylen].msg_count = b->msg_count;
-    (state->entry)[state->entrylen].msg_unread = b->msg_unread;
+    (state->entry)[state->entrylen].new = np->b->new;
+    (state->entry)[state->entrylen].msg_count = np->b->msg_count;
+    (state->entry)[state->entrylen].msg_unread = np->b->msg_unread;
   }
 
   (state->entrylen)++;
index c20e5b18e075bf7072cdb0fbfc8185f35dd97d83..71a1b90ffe547cf324508083a74452a407aff24d 100644 (file)
@@ -621,7 +621,6 @@ static void cmd_parse_search(struct ImapData *idata, const char *s)
 static void cmd_parse_status(struct ImapData *idata, char *s)
 {
   char *value = NULL;
-  struct Buffy *inc = NULL;
   struct ImapMbox mx;
   struct ImapStatus *status = NULL;
   unsigned int olduv, oldun;
@@ -713,14 +712,15 @@ static void cmd_parse_status(struct ImapData *idata, char *s)
   mutt_debug(3, "Running default STATUS handler\n");
 
   /* should perhaps move this code back to imap_buffy_check */
-  for (inc = Incoming; inc; inc = inc->next)
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
-    if (inc->magic != MUTT_IMAP)
+    if (np->b->magic != MUTT_IMAP)
       continue;
 
-    if (imap_parse_path(inc->path, &mx) < 0)
+    if (imap_parse_path(np->b->path, &mx) < 0)
     {
-      mutt_debug(1, "Error parsing mailbox %s, skipping\n", inc->path);
+      mutt_debug(1, "Error parsing mailbox %s, skipping\n", np->b->path);
       continue;
     }
 
@@ -759,18 +759,18 @@ static void cmd_parse_status(struct ImapData *idata, char *s)
           new = (status->unseen > 0);
 
 #ifdef USE_SIDEBAR
-        if ((inc->new != new) || (inc->msg_count != status->messages) ||
-            (inc->msg_unread != status->unseen))
+        if ((np->b->new != new) || (np->b->msg_count != status->messages) ||
+            (np->b->msg_unread != status->unseen))
         {
           mutt_menu_set_current_redraw(REDRAW_SIDEBAR);
         }
 #endif
-        inc->new = new;
+        np->b->new = new;
         if (new_msg_count)
-          inc->msg_count = status->messages;
-        inc->msg_unread = status->unseen;
+          np->b->msg_count = status->messages;
+        np->b->msg_unread = status->unseen;
 
-        if (inc->new)
+        if (np->b->new)
         {
           /* force back to keep detecting new mail until the mailbox is
              opened */
index c66cfe0eea7aa66d1af7c28e9c128f969a018e6f..6fe1484d8b0ce7375d5e62ee64e603c353dc5a41 100644 (file)
@@ -538,24 +538,24 @@ static size_t longest_common_prefix(char *dest, const char *src, size_t start, s
  */
 static int complete_hosts(char *buf, size_t buflen)
 {
-  struct Buffy *mailbox = NULL;
   struct Connection *conn = NULL;
   int rc = -1;
   size_t matchlen;
 
   matchlen = mutt_str_strlen(buf);
-  for (mailbox = Incoming; mailbox; mailbox = mailbox->next)
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
-    if (mutt_str_strncmp(buf, mailbox->path, matchlen) == 0)
+    if (mutt_str_strncmp(buf, np->b->path, matchlen) != 0)
+      continue;
+
+    if (rc)
     {
-      if (rc)
-      {
-        mutt_str_strfcpy(buf, mailbox->path, buflen);
-        rc = 0;
-      }
-      else
-        longest_common_prefix(buf, mailbox->path, matchlen, buflen);
+      mutt_str_strfcpy(buf, np->b->path, buflen);
+      rc = 0;
     }
+    else
+      longest_common_prefix(buf, np->b->path, matchlen, buflen);
   }
 
   TAILQ_FOREACH(conn, mutt_socket_head(), entries)
@@ -1426,27 +1426,27 @@ int imap_buffy_check(int check_stats)
 {
   struct ImapData *idata = NULL;
   struct ImapData *lastdata = NULL;
-  struct Buffy *mailbox = NULL;
   char name[LONG_STRING];
   char command[LONG_STRING];
   char munged[LONG_STRING];
   int buffies = 0;
 
-  for (mailbox = Incoming; mailbox; mailbox = mailbox->next)
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
     /* Init newly-added mailboxes */
-    if (!mailbox->magic)
+    if (!np->b->magic)
     {
-      if (mx_is_imap(mailbox->path))
-        mailbox->magic = MUTT_IMAP;
+      if (mx_is_imap(np->b->path))
+        np->b->magic = MUTT_IMAP;
     }
 
-    if (mailbox->magic != MUTT_IMAP)
+    if (np->b->magic != MUTT_IMAP)
       continue;
 
-    if (get_mailbox(mailbox->path, &idata, name, sizeof(name)) < 0)
+    if (get_mailbox(np->b->path, &idata, name, sizeof(name)) < 0)
     {
-      mailbox->new = false;
+      np->b->new = false;
       continue;
     }
 
@@ -1456,7 +1456,7 @@ int imap_buffy_check(int check_stats)
      * mailbox's, and shouldn't expand to INBOX in that case. #3216. */
     if (idata->mailbox && (imap_mxcmp(name, idata->mailbox) == 0))
     {
-      mailbox->new = false;
+      np->b->new = false;
       continue;
     }
 
@@ -1506,9 +1506,9 @@ int imap_buffy_check(int check_stats)
   }
 
   /* collect results */
-  for (mailbox = Incoming; mailbox; mailbox = mailbox->next)
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
-    if (mailbox->magic == MUTT_IMAP && mailbox->new)
+    if ((np->b->magic == MUTT_IMAP) && np->b->new)
       buffies++;
   }
 
diff --git a/init.c b/init.c
index 6996999ce3ba107c84d378e2fdc638bb65148068..acf359bee0d089dadca946ef0dcbce079db13479 100644 (file)
--- a/init.c
+++ b/init.c
@@ -1762,7 +1762,7 @@ static int parse_set(struct Buffer *buf, struct Buffer *s, unsigned long data,
           {
             char scratch[PATH_MAX];
             mutt_str_strfcpy(scratch, buf->data, sizeof(scratch));
-            
+
             if (mutt_str_strcmp(buf->data, "builtin") != 0)
             {
               mutt_expand_path(scratch, sizeof(scratch));
@@ -3310,11 +3310,12 @@ int mutt_init(bool skip_sys_rc, struct ListHead *commands)
   if (VirtualSpoolfile)
   {
     /* Find the first virtual folder and open it */
-    for (struct Buffy *b = Incoming; b; b = b->next)
+    struct BuffyNode *bp = NULL;
+    STAILQ_FOREACH(bp, &BuffyList, entries)
     {
-      if (b->magic == MUTT_NOTMUCH)
+      if (bp->b->magic == MUTT_NOTMUCH)
       {
-        cs_str_string_set(Config, "spoolfile", b->path, NULL);
+        cs_str_string_set(Config, "spoolfile", bp->b->path, NULL);
         mutt_sb_toggle_virtual();
         break;
       }
diff --git a/main.c b/main.c
index f6e37e959220081032770b1189955a27cb1fe9a8..ac5621b173550d80f86be780d5a7a5b836fdb21e 100644 (file)
--- a/main.c
+++ b/main.c
@@ -1140,7 +1140,7 @@ int main(int argc, char *argv[], char *envp[])
       }
       else
 #endif
-          if (!Incoming)
+          if (STAILQ_EMPTY(&BuffyList))
       {
         mutt_error(_("No incoming mailboxes defined."));
         goto main_curses; // TEST39: neomutt -n -F /dev/null -y
index a9115431761ea1a5da8914047e3800e2734f6d55..ed5076c0117b71db6a5264ac187805afc286934c 100644 (file)
@@ -2277,15 +2277,18 @@ done:
  */
 char *nm_get_description(struct Context *ctx)
 {
-  for (struct Buffy *b = Incoming; b; b = b->next)
-    if (b->desc && (strcmp(b->path, ctx->path) == 0))
-      return b->desc;
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
+  {
+    if (np->b->desc && (strcmp(np->b->path, ctx->path) == 0))
+      return np->b->desc;
+  }
 
   return NULL;
 }
 
 /**
- * nm_description_to_path - Find a path from a folder's description
+ * nm_desc&ription_to_path - Find a path from a folder's description
  * @param desc   Description
  * @param buf    Buffer for path
  * @param buflen Length of buffer
@@ -2297,11 +2300,12 @@ int nm_description_to_path(const char *desc, char *buf, size_t buflen)
   if (!desc || !buf || (buflen == 0))
     return -EINVAL;
 
-  for (struct Buffy *b = Incoming; b; b = b->next)
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
-    if ((b->magic == MUTT_NOTMUCH) && b->desc && (strcmp(desc, b->desc) == 0))
+    if ((np->b->magic == MUTT_NOTMUCH) && np->b->desc && (strcmp(desc, np->b->desc) == 0))
     {
-      strncpy(buf, b->path, buflen);
+      strncpy(buf, np->b->path, buflen);
       buf[buflen - 1] = '\0';
       return 0;
     }
index 80c887714c313c1384ed9f6a40fded4786f03d6e..a3ecb7e65018c54de096a6bcf370a679d893a954 100644 (file)
--- a/sidebar.c
+++ b/sidebar.c
@@ -420,13 +420,16 @@ static void update_entries_visibility(void)
  */
 static void unsort_entries(void)
 {
-  struct Buffy *cur = Incoming;
   int i = 0;
 
-  while (cur && (i < EntryCount))
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
+    if (i >= EntryCount)
+      break;
+
     int j = i;
-    while ((j < EntryCount) && (Entries[j]->buffy != cur))
+    while ((j < EntryCount) && (Entries[j]->buffy != np->b))
       j++;
     if (j < EntryCount)
     {
@@ -438,7 +441,6 @@ static void unsort_entries(void)
       }
       i++;
     }
-    cur = cur->next;
   }
 }
 
@@ -815,7 +817,7 @@ static void fill_empty_space(int first_row, int num_rows, int div_width, int num
  * Display a list of mailboxes in a panel on the left.  What's displayed will
  * depend on our index markers: TopBuffy, OpnBuffy, HilBuffy, BotBuffy.
  * On the first run they'll be NULL, so we display the top of NeoMutt's list
- * (Incoming).
+ * (BuffyList).
  *
  * * TopBuffy - first visible mailbox
  * * BotBuffy - last  visible mailbox
@@ -1000,8 +1002,13 @@ void mutt_sb_draw(void)
   int div_width = draw_divider(num_rows, num_cols);
 
   if (!Entries)
-    for (struct Buffy *b = Incoming; b; b = b->next)
-      mutt_sb_notify_mailbox(b, 1);
+  {
+    struct BuffyNode *np = NULL;
+    STAILQ_FOREACH(np, &BuffyList, entries)
+    {
+      mutt_sb_notify_mailbox(np->b, 1);
+    }
+  }
 
   if (!prepare_sidebar(num_rows))
   {
@@ -1076,19 +1083,18 @@ void mutt_sb_change_mailbox(int op)
  */
 void mutt_sb_set_buffystats(const struct Context *ctx)
 {
-  /* Even if the sidebar's hidden,
-   * we should take note of the new data. */
-  struct Buffy *b = Incoming;
-  if (!ctx || !b)
+  if (!ctx)
     return;
 
-  for (; b; b = b->next)
+  /* Even if the sidebar's hidden, we should take note of the new data. */
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
-    if (mutt_str_strcmp(b->realpath, ctx->realpath) == 0)
+    if (mutt_str_strcmp(np->b->realpath, ctx->realpath) == 0)
     {
-      b->msg_unread = ctx->unread;
-      b->msg_count = ctx->msgcount;
-      b->msg_flagged = ctx->flagged;
+      np->b->msg_unread = ctx->unread;
+      np->b->msg_count = ctx->msgcount;
+      np->b->msg_flagged = ctx->flagged;
       break;
     }
   }
@@ -1223,13 +1229,14 @@ void mutt_sb_toggle_virtual(void)
   EntryCount = 0;
   FREE(&Entries);
   EntryLen = 0;
-  for (struct Buffy *b = Incoming; b; b = b->next)
+  struct BuffyNode *np = NULL;
+  STAILQ_FOREACH(np, &BuffyList, entries)
   {
     /* and reintroduce the ones that are visible */
-    if (((b->magic == MUTT_NOTMUCH) && (sidebar_source == SB_SRC_VIRT)) ||
-        ((b->magic != MUTT_NOTMUCH) && (sidebar_source == SB_SRC_INCOMING)))
+    if (((np->b->magic == MUTT_NOTMUCH) && (sidebar_source == SB_SRC_VIRT)) ||
+        ((np->b->magic != MUTT_NOTMUCH) && (sidebar_source == SB_SRC_INCOMING)))
     {
-      mutt_sb_notify_mailbox(b, true);
+      mutt_sb_notify_mailbox(np->b, true);
     }
   }