]> granicus.if.org Git - neomutt/commitdiff
move parse_mailboxes()
authorRichard Russon <rich@flatcap.org>
Sun, 20 Jan 2019 16:46:19 +0000 (16:46 +0000)
committerRichard Russon <rich@flatcap.org>
Fri, 8 Feb 2019 16:32:52 +0000 (16:32 +0000)
This function has dependencies on Context and inotify().

ChangeLog.md
init.c
init.h
mailbox.c
mailbox.h

index e9305b3ce85ae3557b86886d3af9b2907c033110..6470d63f1fdb7d83b3fdf6a4a6379fa4cdad8821 100644 (file)
   - More sophisticated check for BDB version + support for DB6 (non default)
 * Tidy
   - drop VirtIncoming
-  - split mutt_parse_mailboxes into mutt_parse_unmailboxes
+  - split parse_mailboxes into parse_unmailboxes
   - tidy some mailbox code
   - tidy the version strings
 * Upstream
diff --git a/init.c b/init.c
index 7158d7e00927e2301258d1341a32be454747790d..23309fed30e7f3c0cef21a20149d2d06674b2ab1 100644 (file)
--- a/init.c
+++ b/init.c
 #include "email/lib.h"
 #include "mutt.h"
 #include "init.h"
+#include "account.h"
 #include "alias.h"
 #include "context.h"
 #include "filter.h"
 #include "hcache/hcache.h"
 #include "keymap.h"
+#include "monitor.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
 #include "mutt_window.h"
@@ -1321,6 +1323,92 @@ bail:
   return MUTT_CMD_ERROR;
 }
 
+/**
+ * parse_mailboxes - Parse the 'mailboxes' command - Implements ::command_t
+ *
+ * This is also used by 'virtual-mailboxes'.
+ */
+static enum CommandResult parse_mailboxes(struct Buffer *buf, struct Buffer *s,
+                                          unsigned long data, struct Buffer *err)
+{
+  while (MoreArgs(s))
+  {
+    struct Mailbox *m = mailbox_new();
+
+    if (data & MUTT_NAMED)
+    {
+      mutt_extract_token(buf, s, 0);
+      if (buf->data && *buf->data)
+      {
+        m->desc = mutt_str_strdup(buf->data);
+      }
+      else
+      {
+        mailbox_free(&m);
+        continue;
+      }
+    }
+
+    mutt_extract_token(buf, s, 0);
+    if (mutt_buffer_is_empty(buf))
+    {
+      /* Skip empty tokens. */
+      mailbox_free(&m);
+      continue;
+    }
+
+    mutt_str_strfcpy(m->path, buf->data, sizeof(m->path));
+    /* int rc = */ mx_path_canon2(m, Folder);
+
+    bool new_account = false;
+    struct Account *a = mx_ac_find(m);
+    if (!a)
+    {
+      a = account_new();
+      a->magic = m->magic;
+      TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
+      new_account = true;
+    }
+
+    if (!new_account)
+    {
+      struct Mailbox *old_m = mx_mbox_find(a, m->realpath);
+      if (old_m)
+      {
+        if (old_m->flags == MB_HIDDEN)
+        {
+          old_m->flags = MB_NORMAL;
+          mutt_sb_notify_mailbox(old_m, true);
+          struct MailboxNode *mn = mutt_mem_calloc(1, sizeof(*mn));
+          mn->m = old_m;
+          STAILQ_INSERT_TAIL(&AllMailboxes, mn, entries);
+        }
+        mailbox_free(&m);
+        continue;
+      }
+    }
+
+    if (mx_ac_add(a, m) < 0)
+    {
+      //error
+      mailbox_free(&m);
+      continue;
+    }
+
+    struct MailboxNode *mn = mutt_mem_calloc(1, sizeof(*mn));
+    mn->m = m;
+    STAILQ_INSERT_TAIL(&AllMailboxes, mn, entries);
+
+#ifdef USE_SIDEBAR
+    mutt_sb_notify_mailbox(m, true);
+#endif
+#ifdef USE_INOTIFY
+    mutt_monitor_add(m);
+#endif
+  }
+  return MUTT_CMD_SUCCESS;
+}
+
 /**
  * parse_my_hdr - Parse the 'my_hdr' command - Implements ::command_t
  */
@@ -2290,6 +2378,76 @@ static enum CommandResult parse_unlists(struct Buffer *buf, struct Buffer *s,
   return MUTT_CMD_SUCCESS;
 }
 
+/**
+ * parse_unmailboxes - Parse the 'unmailboxes' command - Implements ::command_t
+ *
+ * This is also used by 'unvirtual-mailboxes'
+ */
+static enum CommandResult parse_unmailboxes(struct Buffer *buf, struct Buffer *s,
+                                            unsigned long data, struct Buffer *err)
+{
+  char tmp[PATH_MAX];
+  bool tmp_valid = false;
+  bool clear_all = false;
+
+  while (!clear_all && MoreArgs(s))
+  {
+    mutt_extract_token(buf, s, 0);
+
+    if (mutt_str_strcmp(buf->data, "*") == 0)
+    {
+      clear_all = true;
+      tmp_valid = false;
+    }
+    else
+    {
+      mutt_str_strfcpy(tmp, buf->data, sizeof(tmp));
+      mutt_expand_path(tmp, sizeof(tmp));
+      tmp_valid = true;
+    }
+
+    struct MailboxNode *np = NULL;
+    struct MailboxNode *nptmp = NULL;
+    STAILQ_FOREACH_SAFE(np, &AllMailboxes, entries, nptmp)
+    {
+      /* Decide whether to delete all normal mailboxes or all virtual */
+      bool virt = ((np->m->magic == MUTT_NOTMUCH) && (data & MUTT_VIRTUAL));
+      bool norm = ((np->m->magic != MUTT_NOTMUCH) && !(data & MUTT_VIRTUAL));
+      bool clear_this = clear_all && (virt || norm);
+
+      /* Compare against path or desc? Ensure 'tmp' is valid */
+      if (!clear_this && tmp_valid)
+      {
+        clear_this = (mutt_str_strcasecmp(tmp, np->m->path) == 0) ||
+                     (mutt_str_strcasecmp(tmp, np->m->desc) == 0);
+      }
+
+      if (clear_this)
+      {
+#ifdef USE_SIDEBAR
+        mutt_sb_notify_mailbox(np->m, false);
+#endif
+#ifdef USE_INOTIFY
+        mutt_monitor_remove(np->m);
+#endif
+        if (Context && (Context->mailbox == np->m))
+        {
+          np->m->flags |= MB_HIDDEN;
+        }
+        else
+        {
+          mx_ac_remove(np->m);
+          mailbox_free(&np->m);
+        }
+        STAILQ_REMOVE(&AllMailboxes, np, MailboxNode, entries);
+        FREE(&np);
+        continue;
+      }
+    }
+  }
+  return MUTT_CMD_SUCCESS;
+}
+
 /**
  * parse_unmy_hdr - Parse the 'unmy_hdr' command - Implements ::command_t
  */
diff --git a/init.h b/init.h
index 83892262ce5b564273ac76eea784f3e75129ecea..a8ea7c7d45275dcdfb406113fa1b09d6d63c9eb6 100644 (file)
--- a/init.h
+++ b/init.h
@@ -102,6 +102,10 @@ enum MuttSetCommand
   MUTT_SET_RESET, ///< default is to reset all vars to default
 };
 
+/* parameter to parse_mailboxes */
+#define MUTT_NAMED   (1 << 0)
+#define MUTT_VIRTUAL (1 << 1)
+
 #define UL (unsigned long)
 #define IP (intptr_t)
 #endif /* _MAKEDOC */
@@ -4757,6 +4761,7 @@ static enum CommandResult parse_group           (struct Buffer *buf, struct Buff
 static enum CommandResult parse_ifdef           (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 static enum CommandResult parse_ignore          (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 static enum CommandResult parse_lists           (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
+static enum CommandResult parse_mailboxes       (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 static enum CommandResult parse_my_hdr          (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 #ifdef USE_SIDEBAR
 static enum CommandResult parse_path_list       (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
@@ -4780,6 +4785,7 @@ static enum CommandResult parse_unalternates    (struct Buffer *buf, struct Buff
 static enum CommandResult parse_unattachments   (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 static enum CommandResult parse_unignore        (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 static enum CommandResult parse_unlists         (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
+static enum CommandResult parse_unmailboxes     (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 static enum CommandResult parse_unmy_hdr        (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 static enum CommandResult parse_unreplace_list  (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
 static enum CommandResult parse_unstailq        (struct Buffer *buf, struct Buffer *s, unsigned long data, struct Buffer *err);
@@ -4828,14 +4834,14 @@ const struct Command Commands[] = {
   { "lua-source",          mutt_lua_source_file,   0 },
 #endif
   { "macro",               mutt_parse_macro,       0 },
-  { "mailboxes",           mutt_parse_mailboxes,   0 },
+  { "mailboxes",           parse_mailboxes,        0 },
   { "mailto_allow",        parse_stailq,           UL &MailToAllow },
   { "mbox-hook",           mutt_parse_hook,        MUTT_MBOX_HOOK },
   { "message-hook",        mutt_parse_hook,        MUTT_MESSAGE_HOOK },
   { "mime_lookup",         parse_stailq,           UL &MimeLookupList },
   { "mono",                mutt_parse_mono,        0 },
   { "my_hdr",              parse_my_hdr,           0 },
-  { "named-mailboxes",     mutt_parse_mailboxes,   MUTT_NAMED },
+  { "named-mailboxes",     parse_mailboxes,        MUTT_NAMED },
   { "nospam",              parse_spam_list,        MUTT_NOSPAM },
 #ifdef USE_COMPRESSED
   { "open-hook",           mutt_parse_hook,        MUTT_OPEN_HOOK },
@@ -4879,7 +4885,7 @@ const struct Command Commands[] = {
   { "unhook",              mutt_parse_unhook,      0 },
   { "unignore",            parse_unignore,         0 },
   { "unlists",             parse_unlists,          0 },
-  { "unmailboxes",         mutt_parse_unmailboxes, 0 },
+  { "unmailboxes",         parse_unmailboxes,      0 },
   { "unmailto_allow",      parse_unstailq,         UL &MailToAllow },
   { "unmime_lookup",       parse_unstailq,         UL &MimeLookupList },
   { "unmono",              mutt_parse_unmono,      0 },
@@ -4896,8 +4902,8 @@ const struct Command Commands[] = {
   { "unsubscribe-from",    parse_unsubscribe_from, 0 },
 #endif
 #ifdef USE_NOTMUCH
-  { "unvirtual-mailboxes", mutt_parse_unmailboxes, MUTT_VIRTUAL },
-  { "virtual-mailboxes",   mutt_parse_mailboxes,   MUTT_VIRTUAL | MUTT_NAMED },
+  { "unvirtual-mailboxes", parse_unmailboxes,      MUTT_VIRTUAL },
+  { "virtual-mailboxes",   parse_mailboxes,        MUTT_VIRTUAL | MUTT_NAMED },
 #endif
   { NULL,                  NULL,                   0 },
 };
index c7f83ef26022b4a576efcecfbb0272c6c1960d9b..4ebef89b85eca46a4a16821cf582e4eee30dcceb 100644 (file)
--- a/mailbox.c
+++ b/mailbox.c
@@ -319,162 +319,6 @@ void mutt_update_mailbox(struct Mailbox *m)
     m->size = 0;
 }
 
-/**
- * mutt_parse_mailboxes - Parse the 'mailboxes' command - Implements ::command_t
- *
- * This is also used by 'virtual-mailboxes'.
- */
-enum CommandResult mutt_parse_mailboxes(struct Buffer *buf, struct Buffer *s,
-                                        unsigned long data, struct Buffer *err)
-{
-  while (MoreArgs(s))
-  {
-    struct Mailbox *m = mailbox_new();
-
-    if (data & MUTT_NAMED)
-    {
-      mutt_extract_token(buf, s, 0);
-      if (buf->data && *buf->data)
-      {
-        m->desc = mutt_str_strdup(buf->data);
-      }
-      else
-      {
-        mailbox_free(&m);
-        continue;
-      }
-    }
-
-    mutt_extract_token(buf, s, 0);
-    if (mutt_buffer_is_empty(buf))
-    {
-      /* Skip empty tokens. */
-      mailbox_free(&m);
-      continue;
-    }
-
-    mutt_str_strfcpy(m->path, buf->data, sizeof(m->path));
-    /* int rc = */ mx_path_canon2(m, Folder);
-
-    bool new_account = false;
-    struct Account *a = mx_ac_find(m);
-    if (!a)
-    {
-      a = account_new();
-      a->magic = m->magic;
-      TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
-      new_account = true;
-    }
-
-    if (!new_account)
-    {
-      struct Mailbox *old_m = mx_mbox_find(a, m->realpath);
-      if (old_m)
-      {
-        if (old_m->flags == MB_HIDDEN)
-        {
-          old_m->flags = MB_NORMAL;
-          mutt_sb_notify_mailbox(old_m, true);
-          struct MailboxNode *mn = mutt_mem_calloc(1, sizeof(*mn));
-          mn->m = old_m;
-          STAILQ_INSERT_TAIL(&AllMailboxes, mn, entries);
-        }
-        mailbox_free(&m);
-        continue;
-      }
-    }
-
-    if (mx_ac_add(a, m) < 0)
-    {
-      //error
-      mailbox_free(&m);
-      continue;
-    }
-
-    struct MailboxNode *mn = mutt_mem_calloc(1, sizeof(*mn));
-    mn->m = m;
-    STAILQ_INSERT_TAIL(&AllMailboxes, mn, entries);
-
-#ifdef USE_SIDEBAR
-    mutt_sb_notify_mailbox(m, true);
-#endif
-#ifdef USE_INOTIFY
-    mutt_monitor_add(m);
-#endif
-  }
-  return MUTT_CMD_SUCCESS;
-}
-
-/**
- * mutt_parse_unmailboxes - Parse the 'unmailboxes' command - Implements ::command_t
- *
- * This is also used by 'unvirtual-mailboxes'
- */
-enum CommandResult mutt_parse_unmailboxes(struct Buffer *buf, struct Buffer *s,
-                                          unsigned long data, struct Buffer *err)
-{
-  char tmp[PATH_MAX];
-  bool tmp_valid = false;
-  bool clear_all = false;
-
-  while (!clear_all && MoreArgs(s))
-  {
-    mutt_extract_token(buf, s, 0);
-
-    if (mutt_str_strcmp(buf->data, "*") == 0)
-    {
-      clear_all = true;
-      tmp_valid = false;
-    }
-    else
-    {
-      mutt_str_strfcpy(tmp, buf->data, sizeof(tmp));
-      mutt_expand_path(tmp, sizeof(tmp));
-      tmp_valid = true;
-    }
-
-    struct MailboxNode *np = NULL;
-    struct MailboxNode *nptmp = NULL;
-    STAILQ_FOREACH_SAFE(np, &AllMailboxes, entries, nptmp)
-    {
-      /* Decide whether to delete all normal mailboxes or all virtual */
-      bool virt = ((np->m->magic == MUTT_NOTMUCH) && (data & MUTT_VIRTUAL));
-      bool norm = ((np->m->magic != MUTT_NOTMUCH) && !(data & MUTT_VIRTUAL));
-      bool clear_this = clear_all && (virt || norm);
-
-      /* Compare against path or desc? Ensure 'tmp' is valid */
-      if (!clear_this && tmp_valid)
-      {
-        clear_this = (mutt_str_strcasecmp(tmp, np->m->path) == 0) ||
-                     (mutt_str_strcasecmp(tmp, np->m->desc) == 0);
-      }
-
-      if (clear_this)
-      {
-#ifdef USE_SIDEBAR
-        mutt_sb_notify_mailbox(np->m, false);
-#endif
-#ifdef USE_INOTIFY
-        mutt_monitor_remove(np->m);
-#endif
-        if (Context && (Context->mailbox == np->m))
-        {
-          np->m->flags |= MB_HIDDEN;
-        }
-        else
-        {
-          mx_ac_remove(np->m);
-          mailbox_free(&np->m);
-        }
-        STAILQ_REMOVE(&AllMailboxes, np, MailboxNode, entries);
-        FREE(&np);
-        continue;
-      }
-    }
-  }
-  return MUTT_CMD_SUCCESS;
-}
-
 /**
  * mutt_mailbox_check - Check all AllMailboxes for new mail
  * @param m_cur Current Mailbox
index c8ef9e82ea17a42470e5495e4a4db1cce2e5223c..cb779f088978918f32af2bc8ade897e2933c19db 100644 (file)
--- a/mailbox.h
+++ b/mailbox.h
@@ -42,10 +42,6 @@ extern bool  MailCheckStats;
 extern short MailCheckStatsInterval;
 extern bool  MaildirCheckCur;
 
-/* parameter to mutt_parse_mailboxes */
-#define MUTT_NAMED   (1 << 0)
-#define MUTT_VIRTUAL (1 << 1)
-
 #define MB_NORMAL 0
 #define MB_HIDDEN 1
 
@@ -179,8 +175,6 @@ void mutt_mailbox(struct Mailbox *m_cur, char *s, size_t slen);
 bool mutt_mailbox_list(void);
 int mutt_mailbox_check(struct Mailbox *m_cur, int force);
 bool mutt_mailbox_notify(struct Mailbox *m_cur);
-enum CommandResult mutt_parse_mailboxes(struct Buffer *path, struct Buffer *s, unsigned long data, struct Buffer *err);
-enum CommandResult mutt_parse_unmailboxes(struct Buffer *path, struct Buffer *s, unsigned long data, struct Buffer *err);
 void mutt_mailbox_changed(struct Mailbox *m, enum MailboxNotification action);
 
 #endif /* MUTT_MAILBOX_H */