]> granicus.if.org Git - neomutt/commitdiff
split mutt_parse_mailboxes into mutt_parse_unmailboxes
authorRichard Russon <rich@flatcap.org>
Tue, 20 Jun 2017 09:55:11 +0000 (10:55 +0100)
committerRichard Russon <rich@flatcap.org>
Tue, 20 Jun 2017 12:14:42 +0000 (13:14 +0100)
Split mutt_parse_mailboxes into two functions: one to add, one to remove.
There's not much overlap in the two functions and separating them
simplifies the logic.

Where unmailboxes used to use two loops, there's now only one.

buffy.c
buffy.h
init.h
protos.h

diff --git a/buffy.c b/buffy.c
index dd30b44cf273fb61ab6d587444bc2aa91af10b58..b30b628c9071e40f5546f20da683dbcbffa3341d 100644 (file)
--- a/buffy.c
+++ b/buffy.c
@@ -511,7 +511,7 @@ 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, *tmp1 = NULL;
+  struct Buffy **b = NULL;
   char buf[_POSIX_PATH_MAX];
   struct stat sb;
   char f1[PATH_MAX];
@@ -522,20 +522,6 @@ int mutt_parse_mailboxes(struct Buffer *path, struct Buffer *s,
     mutt_extract_token(path, s, 0);
     strfcpy(buf, path->data, sizeof(buf));
 
-    if (data == MUTT_UNMAILBOXES && (mutt_strcmp(buf, "*") == 0))
-    {
-      for (b = &Incoming; *b;)
-      {
-        tmp1 = (*b)->next;
-#ifdef USE_SIDEBAR
-        mutt_sb_notify_mailbox(*b, 0);
-#endif
-        buffy_free(b);
-        *b = tmp1;
-      }
-      return 0;
-    }
-
     mutt_expand_path(buf, sizeof(buf));
 
     /* Skip empty tokens. */
@@ -553,27 +539,8 @@ int mutt_parse_mailboxes(struct Buffer *path, struct Buffer *s,
       }
     }
 
-    if (data == MUTT_UNMAILBOXES)
-    {
-      if (*b)
-      {
-        tmp1 = (*b)->next;
-#ifdef USE_SIDEBAR
-        mutt_sb_notify_mailbox(*b, 0);
-#endif
-        buffy_free(b);
-        *b = tmp1;
-      }
-      continue;
-    }
-
     if (!*b)
-    {
       *b = buffy_new(buf);
-#ifdef USE_SIDEBAR
-      mutt_sb_notify_mailbox(*b, 1);
-#endif
-    }
 
     (*b)->new = false;
     (*b)->notified = true;
@@ -581,7 +548,7 @@ int mutt_parse_mailboxes(struct Buffer *path, struct Buffer *s,
 
     /* for check_mbox_size, it is important that if the folder is new (tested by
      * 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.
+     * that it increased. without check_mbox_size we probably don't care.
      */
     if (option(OPTCHECKMBOXSIZE) && stat((*b)->path, &sb) == 0 &&
         !test_new_folder((*b)->path))
@@ -591,6 +558,51 @@ int mutt_parse_mailboxes(struct Buffer *path, struct Buffer *s,
     }
     else
       (*b)->size = 0;
+
+#ifdef USE_SIDEBAR
+    mutt_sb_notify_mailbox(*b, 1);
+#endif
+  }
+  return 0;
+}
+
+int mutt_parse_unmailboxes(struct Buffer *path, struct Buffer *s,
+                           unsigned long data, struct Buffer *err)
+{
+  char buf[_POSIX_PATH_MAX];
+  bool clear_all = false;
+
+  while (!clear_all && MoreArgs(s))
+  {
+    mutt_extract_token(path, s, 0);
+
+    if (mutt_strcmp(path->data, "*") == 0)
+    {
+      clear_all = true;
+    }
+    else
+    {
+      strfcpy(buf, path->data, sizeof(buf));
+      mutt_expand_path(buf, sizeof(buf));
+    }
+
+    for (struct Buffy **b = &Incoming; *b;)
+    {
+      if (clear_all ||
+          (mutt_strcasecmp(buf, (*b)->path) == 0) ||
+          (mutt_strcasecmp(buf, (*b)->desc) == 0))
+      {
+        struct Buffy *next = (*b)->next;
+#ifdef USE_SIDEBAR
+        mutt_sb_notify_mailbox(*b, 0);
+#endif
+        buffy_free(b);
+        *b = next;
+        continue;
+      }
+
+      b = &((*b)->next);
+    }
   }
   return 0;
 }
diff --git a/buffy.h b/buffy.h
index a6dfd2bd85c8ee16f59899257df2b2307530d181..6402082cf5c4252094e962debc2f4719dee05216 100644 (file)
--- a/buffy.h
+++ b/buffy.h
 
 struct stat;
 
-/* parameter to mutt_parse_mailboxes */
-#define MUTT_MAILBOXES   1
-#define MUTT_UNMAILBOXES 2
-
 struct Buffy
 {
   char path[_POSIX_PATH_MAX];
diff --git a/init.h b/init.h
index c55d77f771d6e623b4486b314e06dc4297ec175e..385260569b1ecfff41179c3c644eff35fe34f563 100644 (file)
--- a/init.h
+++ b/init.h
@@ -4566,8 +4566,8 @@ const struct Command Commands[] = {
   { "lua-source",       mutt_lua_source_file,   0 },
 #endif
   { "macro",            mutt_parse_macro,       0 },
-  { "mailboxes",        mutt_parse_mailboxes,   MUTT_MAILBOXES },
-  { "unmailboxes",      mutt_parse_mailboxes,   MUTT_UNMAILBOXES },
+  { "mailboxes",        mutt_parse_mailboxes,   0 },
+  { "unmailboxes",      mutt_parse_unmailboxes, 0 },
 #ifdef USE_NOTMUCH
   { "virtual-mailboxes",mutt_parse_virtual_mailboxes, 0 },
   { "unvirtual-mailboxes",mutt_parse_unvirtual_mailboxes, 0 },
index 476a57c5b732002794547c6ddd900362b8acf846..323c82824c684db1d25c88284f121daf355817ac 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -328,6 +328,7 @@ int mutt_parse_uncolor(struct Buffer *buf, struct Buffer *s, unsigned long data,
 int mutt_parse_hook(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 int mutt_parse_macro(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 int mutt_parse_mailboxes(struct Buffer *path, struct Buffer *s, unsigned long data, struct Buffer *err);
+int mutt_parse_unmailboxes(struct Buffer *path, struct Buffer *s, unsigned long data, struct Buffer *err);
 int mutt_parse_mono(struct Buffer *buff, struct Buffer *s, unsigned long data, struct Buffer *err);
 int mutt_parse_unmono(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 int mutt_parse_push(struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);