From 9e68d6a5f413498c5ce38ecc51e746ab8bd77615 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Tue, 9 Jul 2019 15:12:55 +0100 Subject: [PATCH] account: add mailbox_add() --- account.c | 23 +++++++++++++++++++---- account.h | 1 + compress.c | 6 ------ mx.c | 9 +++++---- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/account.c b/account.c index 252f7e082..9ababa009 100644 --- a/account.c +++ b/account.c @@ -118,6 +118,25 @@ void account_free_config(struct Account *a) FREE(&a->vars); } +/** + * account_mailbox_add - Add a Mailbox to an Account + * @param a Account + * @param m Mailbox to add + * @retval true If Mailbox was added + */ +bool account_mailbox_add(struct Account *a, struct Mailbox *m) +{ + if (!a || !m) + return false; + + m->account = a; + struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np)); + np->mailbox = m; + STAILQ_INSERT_TAIL(&a->mailboxes, np, entries); + + return true; +} + /** * account_mailbox_remove - Remove a Mailbox from an Account * @param a Account @@ -146,10 +165,6 @@ bool account_mailbox_remove(struct Account *a, struct Mailbox *m) } } - if (STAILQ_EMPTY(&a->mailboxes)) - { - neomutt_account_remove(NeoMutt, a); - } return result; } diff --git a/account.h b/account.h index bb230ec51..d0afb7fda 100644 --- a/account.h +++ b/account.h @@ -73,6 +73,7 @@ bool account_add_config(struct Account *a, const struct ConfigSet *cs void account_free(struct Account **ptr); void account_free_config(struct Account *a); int account_get_value(const struct Account *a, size_t vid, struct Buffer *result); +bool account_mailbox_add(struct Account *a, struct Mailbox *m); bool account_mailbox_remove(struct Account *a, struct Mailbox *m); struct Account *account_new(void); int account_set_value(const struct Account *a, size_t vid, intptr_t value, struct Buffer *err); diff --git a/compress.c b/compress.c index 5320d8dc4..6af4e5e22 100644 --- a/compress.c +++ b/compress.c @@ -442,12 +442,6 @@ int comp_ac_add(struct Account *a, struct Mailbox *m) { if (!a || !m || (m->magic != MUTT_COMPRESSED)) return -1; - - m->account = a; - - struct MailboxNode *np = mutt_mem_calloc(1, sizeof(*np)); - np->mailbox = m; - STAILQ_INSERT_TAIL(&a->mailboxes, np, entries); return 0; } diff --git a/mx.c b/mx.c index d35ad094f..4e85a21e2 100644 --- a/mx.c +++ b/mx.c @@ -1573,10 +1573,7 @@ int mx_ac_add(struct Account *a, struct Mailbox *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->mailbox = m; - STAILQ_INSERT_TAIL(&a->mailboxes, np, entries); + account_mailbox_add(a, m); return 0; } @@ -1590,6 +1587,10 @@ int mx_ac_remove(struct Mailbox *m) return -1; account_mailbox_remove(m->account, m); + if (STAILQ_EMPTY(&m->account->mailboxes)) + { + neomutt_account_remove(NeoMutt, m->account); + } return 0; } -- 2.40.0