]> granicus.if.org Git - neomutt/commitdiff
mx: Ensure mailbox is always added to Account->mailboxes
authorMehdi Abaakouk <sileht@sileht.net>
Tue, 11 Dec 2018 20:00:38 +0000 (21:00 +0100)
committerRichard Russon <rich@flatcap.org>
Wed, 12 Dec 2018 11:53:15 +0000 (11:53 +0000)
Currently if the user open a mailbox not in AllMailboxes.
We create a HIDDEN Mailbox and find an account with mx_ac_find().

In this case mx_ac_add is not called and the new Mailbox is not
added to the account.

Also some notmuch, pop and imap specific setup is not done.

This change fixes this

Close #1486

mx.c

diff --git a/mx.c b/mx.c
index 4405ce2ae79ad8d18f6440d81686cfa207ff40e7..81598c3912d89b5abef91c4df53a3f297f0ff0c9 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -273,16 +273,20 @@ struct Context *mx_mbox_open(struct Mailbox *m, const char *path, int flags)
     /* int rc = */ mx_path_canon2(m, Folder);
   }
 
-  if (!m->account)
-    m->account = mx_ac_find(m);
-
   if (!m->account)
   {
-    struct Account *a = account_new();
-    m->account = a;
-    a->magic = m->magic;
-    TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
-    mx_ac_add(a, m);
+    struct Account *a = mx_ac_find(m);
+    if (!a)
+    {
+      a = account_new();
+      a->magic = m->magic;
+      TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
+    }
+    if (mx_ac_add(a, m) < 0)
+    {
+      mailbox_free(&m);
+      return NULL;
+    }
   }
 
 #if 0
@@ -341,20 +345,6 @@ struct Context *mx_mbox_open(struct Mailbox *m, const char *path, int flags)
     return NULL;
   }
 
-  if (!m->account)
-  {
-    struct Account *a = account_new();
-    a->magic = m->magic;
-    TAILQ_INSERT_TAIL(&AllAccounts, a, entries);
-
-    if (mx_ac_add(a, m) < 0)
-    {
-      //error
-      mailbox_free(&m);
-      return NULL;
-    }
-  }
-
   mutt_make_label_hash(m);
 
   /* if the user has a `push' command in their .neomuttrc, or in a folder-hook,