All mx_ops->ac_add() do almost the same thing.
Just move the common code to mx_ac_find()
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);
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;
}
*/
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;
}
*/
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;
}
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;
}
/**
*/
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;
}
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;
}
*/
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;
}
}
- m->account = a;
-
- struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np));
- np->m = m;
- STAILQ_INSERT_TAIL(&a->mailboxes, np, entries);
return 0;
}