]> granicus.if.org Git - neomutt/commitdiff
mx: share code between ac_find implementations
authorMehdi Abaakouk <sileht@sileht.net>
Tue, 11 Dec 2018 19:51:40 +0000 (20:51 +0100)
committerRichard Russon <rich@flatcap.org>
Wed, 12 Dec 2018 11:53:15 +0000 (11:53 +0000)
All mx_ops->ac_add() do almost the same thing.

Just move the common code to mx_ac_find()

imap/imap.c
maildir/shared.c
mbox/mbox.c
mx.c
nntp/nntp.c
notmuch/mutt_notmuch.c
pop/pop.c

index 23ff9207eb98c4ff1bb101057da41738f5acb601..d5d048e7db4c207faae39b239b161f9ba7b288e2 100644 (file)
@@ -1872,13 +1872,10 @@ int imap_ac_add(struct Account *a, struct Mailbox *m)
     if (imap_login(adata) < 0)
       return -1;
 
-    a->magic = MUTT_IMAP;
     a->adata = adata;
     a->free_adata = imap_adata_free;
   }
 
-  m->account = a;
-
   if (!m->mdata)
   {
     struct Url *url = url_parse(m->path);
@@ -1887,10 +1884,6 @@ int imap_ac_add(struct Account *a, struct Mailbox *m)
     m->free_mdata = imap_mdata_free;
     url_free(&url);
   }
-
-  struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
-  np->m = m;
-  STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
   return 0;
 }
 
index de7e7e1fee71d92f4b495eec0c5f74f9ffa97a59..67494a10e083cf476f48b3f84de901afa57a58c5 100644 (file)
@@ -1700,17 +1700,8 @@ struct Account *maildir_ac_find(struct Account *a, const char *path)
  */
 int maildir_ac_add(struct Account *a, struct Mailbox *m)
 {
-  if (!a || !m)
+  if (!a || !m || (m->magic != MUTT_MAILDIR && m->magic != MUTT_MH))
     return -1;
-
-  if (m->magic != MUTT_MAILDIR)
-    return -1;
-
-  m->account = a;
-
-  struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
-  np->m = m;
-  STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
   return 0;
 }
 
index c62bf3731f7ec516198df24379804e7c4daefbe6..d0061eaeda86d102b032bfd60507d4c30b576392 100644 (file)
@@ -915,17 +915,8 @@ struct Account *mbox_ac_find(struct Account *a, const char *path)
  */
 int mbox_ac_add(struct Account *a, struct Mailbox *m)
 {
-  if (!a || !m)
+  if (!a || !m || m->magic != MUTT_MBOX)
     return -1;
-
-  if (m->magic != MUTT_MBOX)
-    return -1;
-
-  m->account = a;
-
-  struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
-  np->m = m;
-  STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
   return 0;
 }
 
diff --git a/mx.c b/mx.c
index 81598c3912d89b5abef91c4df53a3f297f0ff0c9..b6752dbcaa6c130bfb22679b0a4cd1503d50370d 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -1729,7 +1729,14 @@ int mx_ac_add(struct Account *a, struct Mailbox *m)
   if (!a || !m || !m->mx_ops || !m->mx_ops->ac_add)
     return -1;
 
-  return m->mx_ops->ac_add(a, m);
+  if (m->mx_ops->ac_add(a, m) < 0)
+    return -1;
+
+  m->account = a;
+  struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
+  np->m = m;
+  STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
+  return 0;
 }
 
 /**
index 501fcf619e64ff61dafc8224013d7cc5caa2eb93..8773819b512be8e6a3ca0168ed73858cd64dab72 100644 (file)
@@ -2412,17 +2412,8 @@ struct Account *nntp_ac_find(struct Account *a, const char *path)
  */
 int nntp_ac_add(struct Account *a, struct Mailbox *m)
 {
-  if (!a || !m)
+  if (!a || !m || m->magic != MUTT_NNTP)
     return -1;
-
-  if (m->magic != MUTT_NNTP)
-    return -1;
-
-  m->account = a;
-
-  struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
-  np->m = m;
-  STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
   return 0;
 }
 
index 46c7223a2b691c53a351d80ed27ed5ce0fd80074..8252e9dc70d76d22928fa270d8ba95802b9d0a6c 100644 (file)
@@ -2100,16 +2100,10 @@ int nm_ac_add(struct Account *a, struct Mailbox *m)
   if (!a->adata)
   {
     struct NmAccountData *adata = nm_adata_new();
-    a->magic = MUTT_NOTMUCH;
     a->adata = adata;
     a->free_adata = nm_adata_free;
   }
 
-  m->account = a;
-
-  struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
-  np->m = m;
-  STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
   return 0;
 }
 
index 91718b21b1392f02fd5a813cac5b0b9c26e63b53..0a19a76ae49b5a73f98fe975eff4783d7e66c294 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -776,16 +776,12 @@ struct Account *pop_ac_find(struct Account *a, const char *path)
  */
 int pop_ac_add(struct Account *a, struct Mailbox *m)
 {
-  if (!a || !m)
-    return -1;
-
-  if (m->magic != MUTT_POP)
+  if (!a || !m || m->magic != MUTT_POP)
     return -1;
 
   if (!a->adata)
   {
     struct PopAccountData *adata = pop_adata_new();
-    a->magic = MUTT_POP;
     a->adata = adata;
     a->free_adata = pop_adata_free;
 
@@ -809,11 +805,6 @@ int pop_ac_add(struct Account *a, struct Mailbox *m)
     }
   }
 
-  m->account = a;
-
-  struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
-  np->m = m;
-  STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
   return 0;
 }